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

Save chart in DB (MemoryStream)

4 Answers 99 Views
Chart
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 Jul 2011, 10:47 AM
Hi,

I'm trying to find a good way to export/save the chart in the DB. What I tried to do is to read the chart into a MemoryStream, and then convert it to a Byte[] and save it. However, I'm having a few issues with this. I need to save it in different sizes so that the user can get a small/medium/large image later on.

Using this code:
Canvas c = new Canvas();
LayoutRoot.Children.Remove(RadChart1);
c.Children.Add(COGSChart);
Canvas.SetTop(RadChart1, -1000);
LayoutRoot.Children.Add(c);
RadChart1.Height = 600;
RadChart1.Width = 800;
MemoryStream fileStream = new MemoryStream();
 
RadChart1.ExportToImage(fileStream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());
RadChart1.Height = Double.NaN;
RadChart1.Width = Double.NaN;
fileStream.Close();
c.Children.Remove(RadChart1);
LayoutRoot.Children.Remove(c);
LayoutRoot.Children.Add(RadChart1);

However, if I set the height and width to something like 4000 px, I still get a stream back with the same size as if it was 400px. This seems very odd to me, as I would have expected it much bigger than before.

Also, when trying to read it back from DB, I'm unable to produce a image of the data I have for some reason.


How can I solve this?

4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 02 Aug 2011, 07:09 AM
Hi John,

Basically, such an approach simply exports an image, rather than the control itself. Another approach, which would allow saving the complete state of the chart would be to read and persist its properties - width, height, datapoints. Then, when you need to restore it you can create a new control and reuse the saved settings.
Let me know how this approach meets your requirements.

Greetings,
Yavor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
John
Top achievements
Rank 1
answered on 02 Aug 2011, 08:51 AM
Sorry, I wasn't clear enough in my first post. I'm trying to export the Chart as image.

I found out the issue was that I wasn't using the dispatcher. When using that, it works great. However, I need to export the chart to an image in 3 different sizes, small, medium and large, and I'm unable to do so, because I can't change the size inside the dispatcher. And also I can't run the same code 3 times, as I don't know when the first one will stop using the chart object.

Is it possible to solve this? Need to all be in a one click event.
0
Yavor
Telerik team
answered on 04 Aug 2011, 07:48 AM
Hello John,

One possible option in this case would be to use a timer, and start the export operations at different intervals, with enough time for the previous export to complete.

Regards,
Yavor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
John
Top achievements
Rank 1
answered on 04 Aug 2011, 07:59 AM
That seems to be a very bad implementation in my opinion. Is there really no other way? Why would I wanna use a timer when all I wanna do is to export three images from a chart?
Tags
Chart
Asked by
John
Top achievements
Rank 1
Answers by
Yavor
Telerik team
John
Top achievements
Rank 1
Share this question
or