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

Exporting a Chart to Image with prefered size

3 Answers 64 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Patric Svensson
Top achievements
Rank 1
Patric Svensson asked on 07 May 2012, 02:24 PM
Hi,

I am trying to export a RadChart to an image using myRadChart.ExportToImage(stream). This all works very well but I want to change the size of the output image.

So I tried doing:

myChart.Width = 800;
myChart.Height = 600;
myChart.ExportToImage(stream);

However, the output image is still as big as the current browser view is.

Is there a way around this?

Thanks

3 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 10 May 2012, 09:08 AM
Hello Patric,

This is more of a architecture's limitation. If you attempted the same with any other Silverlight control (such as Button) then you would get the same result. This is because even though you are changing the size - a layout pass has not been performed. This is the reason we do not support such a functionality out-of-the-box.
 
However, I can suggest that you try this: wrap the export (and the dispose) in a Dispatcher Invoke. This will delay the export and may be a layout update pass will occur. I have tried this in a simple example and it works. Code below should help:
myChart.Width = 800;
myChart.Height = 600;
 
Dispatcher.BeginInvoke(() =>
{
  myChart.ExportToImage(stream);
   // stream.Close();
});

Another thing you can try is to force the LayoutUpdate:
myChart.Width = 800;
myChart.Height = 600;
 
myChart.UpdateLayout();
myChart.ExportToImage(stream);

I would like to note again that this is a framework's limitation and this is really a hacky way to go around it, so make sure you test this thoroughly before you ship your product.

All the best,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
shankar parshimoni
Top achievements
Rank 1
answered on 12 Sep 2012, 11:19 AM
hello patric ,can you able to place the code here.
0
Petar Marchev
Telerik team
answered on 14 Sep 2012, 08:39 AM
Hello Shukreya,

I have attached a simple project that demonstrates the two approaches.

Kind regards,
Petar Marchev
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
Chart
Asked by
Patric Svensson
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
shankar parshimoni
Top achievements
Rank 1
Share this question
or