Hi there,
We use Telerik charts as part of our Silverlight application.
We would now like add a feature that exports multiple charts to PowerPoint, PDF, etc. in an automated way, at certain time intervals.
Is there some way to get the same Telerik charts generated /rendered on the server side?
I’m not sure if it’s possible to get XAML working on the server, and whether there this can be done withTelerik.
Thanks,
Pete
4 Answers, 1 is accepted
RadCartesianChart can be rendered outside the visual tree with no problem. Take a look at this code:
private RadCartesianChart CreateChart(Size size){ RadCartesianChart chart = new RadCartesianChart(); chart.HorizontalAxis = new CategoricalAxis(); chart.VerticalAxis = new LinearAxis(); BarSeries series = new BarSeries(); series.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint() { Category = "A", Value = 1 }); series.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint() { Category = "B", Value = 2 }); series.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint() { Category = "C", Value = 3 }); chart.Series.Add(series); chart.ApplyTemplate(); chart.Measure(size); chart.Arrange(new Rect(size)); return chart;}This will return a bar chart that can be exported as a picture easily. Here is how:
private Stream Render(FrameworkElement element){ MemoryStream ms = new MemoryStream(); Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(element, ms, new PngBitmapEncoder()); return ms;}Using this code is as easy as:
RadCartesianChart chart = this.CreateChart(new Size(300, 300));Stream ms = this.Render(chart);// Do something with this streamHope this code gets you started!
Regards,
Yavor
Telerik
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 >>
Hi Yavor,
Does this still work? I am on the current latest version 2016.1.217. I can get your example to compile in a [STAThread] console application with the appropriate dependencies. I can see the background color of the RadCartesianChart change when I set a different color for it, but I cannot see the series plotted out in the exported image.
Thanks and regards.
Sudipto
We have not made any changes to the chart that could negatively affect exporting it. Perhaps you need to do some additional preparation prior to exporting the chart into an image. I am attaching a small project that uses a console application to create and export a chart. You can examine the PrepareElementForExport method.
We prefer to keep separate questions in separate threads, so if you have additional questions, please do open a new ticket.
Regards,
Petar Marchev
Telerik