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

Render charts on the server side

4 Answers 81 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Petar
Top achievements
Rank 1
Petar asked on 12 Dec 2013, 07:39 PM

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

Sort by
0
Yavor
Telerik team
answered on 17 Dec 2013, 09:58 AM
Hello Pete,

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 stream

Hope this code gets you started!

Regards,
Yavor
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 >>
0
Sudipto
Top achievements
Rank 1
answered on 09 May 2016, 03:51 PM

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

0
Sudipto
Top achievements
Rank 1
answered on 09 May 2016, 04:02 PM
Should have mentioned that I am trying to use the Telerik WPF library rather than the Silverlight one.
0
Petar Marchev
Telerik team
answered on 10 May 2016, 08:13 AM
Hi 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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
ChartView
Asked by
Petar
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Sudipto
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or