This is a migrated thread and some comments may be shown as answers.

Problem exporting databound chart that isn't visible

7 Answers 84 Views
Chart
This is a migrated thread and some comments may be shown as answers.
David Brubacher
Top achievements
Rank 1
David Brubacher asked on 20 Aug 2010, 06:39 PM
As part of my application I am storing some meta-data on the server. That meta-data needs to contain a chart.
I have a user control that contains all of the logic of the chart, which the user can see at any time just by clicking a button.

I'm trying to generate the same chart and export it to a PNG even if the chart isn't visible
        /// <summary>
        /// Send a chart image when asked
        /// </summary>
        public byte[] MakeChartImage()
        {
            chart.Arrange(new Rect(new Point(0, 0), new Size(1024, 768)));
            var stream = new MemoryStream();
            chart.ExportToImage(stream, new PngBitmapEncoder());
            return stream.ToArray();
       }

I'm using MEF and MVVM, so the cart gets a message that there is new chart data, does a Rebind, then
raises an event to let the calling app know its safe to call the above method.

The chart I get is devoid of all bound data (see attachment).
How do you force the chart to render despite it not being visible?
I've also included a chart as it looks when the user views it.


7 Answers, 1 is accepted

Sort by
0
David Brubacher
Top achievements
Rank 1
answered on 20 Aug 2010, 06:44 PM
This is what the chart should look like (minus the radwindow)
0
David Brubacher
Top achievements
Rank 1
answered on 20 Aug 2010, 09:48 PM
Some progress.

Here is where I generate the meta-data in a view model
        /// <summary>
        /// Report metadata back to the server on what we are querying
        /// </summary>
        /// <param name="ignore">This value isn't used</param>
        private void GenerateData(string ignore)
        {
            var chart = new ChartView();
            chart.DataBound += ChartDataBound;
            _ChartWindow = new RadWindow
                               {
                                   Left = -2000,
                                   Top = -2000,
                                   Width = 1100,
                                   Height = 850,
                                   Content = chart
                               };
            _ChartWindow.Show();
            SendDataToChart(false);
        }

        private void ChartDataBound(object sender, EventArgs e)
        {
            var chart = sender as ChartView;
            if (chart == null)
            {
                _ChartWindow.Close();
                return;
            }
            var usage = new Usage
            {
                ...,
                Chart = chart.MakeChartImage(),
                ...,
            };
            _ChartWindow.Close();
            _Model.SubmitUsage(usage);
        }


and here is the MakeChartImage() method
        /// <summary>
        /// Send a chart image when asked
        /// </summary>
        public byte[] MakeChartImage()
        {
            chart.UpdateLayout();
            var stream = new MemoryStream();
            chart.ExportToImage(stream, new PngBitmapEncoder());
            return stream.ToArray();
        }
The some data it binding but not the bubbles
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 25 Aug 2010, 05:06 PM
Hello David,

Try disabling the chart animations (RadChart.DefaultView.ChartArea.EnableAnimations = false) prior to exporting the image and you should be able to achieve the desired effect.


Greetings,
Bart.
0
David Brubacher
Top achievements
Rank 1
answered on 25 Aug 2010, 06:09 PM
No change unfortunately. Thanks for the suggestion though.
0
Yavor
Telerik team
answered on 26 Aug 2010, 07:59 AM
Hello David,

Based on the supplied information, it is hard to determine what is causing this unwanted behavior. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your implementation, and showing the unwanted behavior. We will review it locally, and advise you further.

All the best,
Yavor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David Brubacher
Top achievements
Rank 1
answered on 29 Sep 2010, 10:20 PM
Sorry for not supplying additional info - circumstances took me away from this project for a while.
I've returned to it today, applied the new service pack and voila! everything works as expected.

Thnk-you very much!
0
Yavor
Telerik team
answered on 04 Oct 2010, 08:46 AM
Hi David,

I am glad that the issue has been resolved, and that the project is working as per your requirements now.
If further questions/issues arise, let us know.

Regards,
Yavor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
David Brubacher
Top achievements
Rank 1
Answers by
David Brubacher
Top achievements
Rank 1
Bartholomeo Rocca
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or