Exporting a Chart to Image with prefered size

4 posts, 0 answers
  1. Patric Svensson
    Patric Svensson avatar
    14 posts
    Member since:
    Nov 2006

    Posted 07 May 2012 Link to this post

    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
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 May 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. shankar parshimoni
    shankar parshimoni avatar
    18 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    hello patric ,can you able to place the code here.
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 14 Sep 2012 Link to this post

    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.

Back to Top