Export functionality of charts

4 posts, 0 answers
  1. Sampada
    Sampada avatar
    44 posts
    Member since:
    Feb 2012

    Posted 24 Jun 2013 Link to this post

    Telerik Team,

    I have a Dashboard with Telerik Silverlight controls used. The Charts in the Dashboard are dynamically created as per user configuration. Now we have a requirement that when the Silverlight Content is loaded on the page followings things should happen:

    1. Create a word document at a particular location on server containing the images of all Charts on our Dashboard(Export to Word).
    2. Create a image in *.png format at a particular location on server of charts.

    Please note that the word document should automatically be created on the silverlight content being loaded every time without requiring any user interaction.

    Please let me know how I can achieve this task.

     

    Thanks in advance.


  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 27 Jun 2013 Link to this post

    Hi Sampada,

    Due to limitation of Silverlight framework, it is not possible to export a control if it is not attached to the visual tree. Additionally this needs to be done, after the chart is fully rendered. However the Silverlight framework does not provide a straight-forward way to know if a visual element is rendered. What you can do is to attach to the RadChart.Loaded event and then using a timer, execute the chart export logic after 1 second. In order to ensure that the chart is rendered, you need to disable the animations:
    this.RadChart1.DefaultView.ChartArea.EnableAnimations = false;

    RadChart provides 
    built-in methods for exporting to several formats. For more advanced scenarios such as exporting to documents (Word, PDF, etc.), you can use the RadDocument control. Here you can find an example of that. After the chart is exported you can use the WebClient API to upload the image/document to the server (Silverlight code is executed on the client machine).

    I hope this helps.

    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Sampada
    Sampada avatar
    44 posts
    Member since:
    Feb 2012

    Posted 28 Jun 2013 Link to this post

    Hi Petar,

    Thanks for the reply

    Could you please provide me a code sample or demo project of your given solution.

    Thanks & regards
    Sampada
  5. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 03 Jul 2013 Link to this post

    Hi Sampada,

    I have attached a sample project. In it the chart is automatically exported to image on page load, and saved in a memory stream for later use. You can save the image on your computer, by clicking the Export button to verify that it is correct.

    Please note that this is not a supported scenario, so be sure to test it extensively.

    In your project, basically you need to replace the UploadImageToServer with your custom upload logic. In it you can use RadDocument, like it is demonstrated in this help topic to export Word, PDF, etc. Here you find an example of how to use WebClient to upload the file(s) to the server.
    You can see for example how I have implemented the ExportButton_Click method, and it should be relatively simple to modify it as per your requirements.
     
    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top