Good news everyone! Exporting Silverlight charts to images has been a common request for our Silverlight chart. I’m glad to announce that the functionality is already done and checked in our development branch. This means that everything is on track for the Q3 2009 release (and maybe a beta release before that!).
But why not for Q2? Well, there are a couple of reasons. Q2 release was still Silverlight 2 based and there were technological difficulties that didn’t allow us to implement this feature. Firstly, Silverlight 2 didn’t have the writeable bitmap class which facilitates rasterizing the chart rendering and secondly there was no way to write to a file. Now that Silverlight 3 is out there are no roadblocks and we’ve implemented the export functionality. I will walk you through it in the next paragraph.
Consider the following code snippet:
//PART 1 - Show the dialog and obtain a stream to the new fileSaveFileDialog dialog = new SaveFileDialog();dialog.DefaultExt = "png";dialog.Filter = "*.png | PNG File";if (!(bool)dialog.ShowDialog()) return;Stream fileStream = dialog.OpenFile();//PART 2 - use the stream to write the file output.RadChart1.ExportToImage(fileStream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());fileStream.Close();
As you can see the code is split into two parts. The first part should be familiar to all silverlight 3 develoeprs. It uses the new SaveFileDialog class to display a save dialog and obtain a reference to a stream to the newly created file. The second part demonstrates how to pass that stream to the RadChart API and export the chart content to a PNG file. Since Silverlight does not have any encoders for PNG or BMP you will need to use the encoders we provided to you along RadChart. These are our own encoders which are implemented according the PNG and BMP specifications. The BMP encoder name is Telerik.Windows.Media.Imaging.BmpBitmapEncoder.
But there’s more! Not only did we implement exporting to PNG and BMP, but there is a way to export to EXCEL and XPS too. To do so you simply need to use a different method:
There are a lot of other things the charting team has been busy with. Stay tuned to the telerik blogs to learn about more exciting features to come out for Q3 2009.
Vladimir Milev is a developer manager.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.