In my WinForms application, I generate a chart using some business and localization routines. The chart works great, but I need to reproduce the exact same chart in a report.
Is there any way to access the actual chart on the report and modify it like I would on a regular Windows Form (preferably through code)?
In addition, does it matter if the chart (which always only appears once) reside in a sub-report or on the master report?
Is there any way to access the actual chart on the report and modify it like I would on a regular Windows Form (preferably through code)?
In addition, does it matter if the chart (which always only appears once) reside in a sub-report or on the master report?
8 Answers, 1 is accepted
0
Hi shovavnik,
In the Q1 2008 release of the Reporting the only way to populate the chart with data is to use a data bound series. Consider this code snippet as an example:
In the service pack 1 which is about to be released in the middle of the month (May, 15th), you will be able to create custom series without the need of data binding it. For exampe:
The rest of the chart's appearance can be customized in the same way as the WinForm's chart but by using the properties and methods exposed by the Chart report item.
Hope this helps.
Regards,
Chavdar
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
In the Q1 2008 release of the Reporting the only way to populate the chart with data is to use a data bound series. Consider this code snippet as an example:
public partial class ChartReport : Report |
{ |
public ChartReport() |
{ |
/// <summary> |
/// Required for telerik Reporting designer support |
/// </summary> |
InitializeComponent(); |
// |
// TODO: Add any constructor code after InitializeComponent call |
// |
this.chart1.Series.Clear(); |
ChartSeries s = new ChartSeries(); |
s.Type = ChartSeriesType.Pie; |
s.DataYColumn = "Value"; |
s.DataLabelsColumn = "Name"; |
this.chart1.Series.Add(s); |
} |
private void chart1_NeedDataSource(object sender, System.EventArgs e) |
{ |
DataTable table = new DataTable(); |
table.Columns.Add("Name", typeof(string)); |
table.Columns.Add("Value", typeof(int)); |
table.Rows.Add(new object[] { "A", 1 }); |
table.Rows.Add(new object[] { "B", 2 }); |
table.Rows.Add(new object[] { "C", 3 }); |
table.Rows.Add(new object[] { "D", 4 }); |
Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender; |
chart.DataSource = table; |
} |
} |
In the service pack 1 which is about to be released in the middle of the month (May, 15th), you will be able to create custom series without the need of data binding it. For exampe:
public partial class ChartReport : Report |
{ |
public ChartReport() |
{ |
/// <summary> |
/// Required for telerik Reporting designer support |
/// </summary> |
InitializeComponent(); |
// |
// TODO: Add any constructor code after InitializeComponent call |
// |
this.chart1.Series.Clear(); |
ChartSeries s = new ChartSeries(); |
s.Type = ChartSeriesType.Pie; |
s.DataYColumn = "Value"; |
s.DataLabelsColumn = "Name"; |
s.AddItem(new ChartSeriesItem(1, "A")); |
s.AddItem(new ChartSeriesItem(2, "B")); |
s.AddItem(new ChartSeriesItem(3, "C")); |
s.AddItem(new ChartSeriesItem(4, "D")); |
this.chart1.Series.Add(s); |
} |
The rest of the chart's appearance can be customized in the same way as the WinForm's chart but by using the properties and methods exposed by the Chart report item.
Hope this helps.
Regards,
Chavdar
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

shovavnik
Top achievements
Rank 1
answered on 08 May 2008, 07:19 AM
I was able to use your example to bind my chart to real data supplied by my business logic layer.
I couldn't find any way to localize the chart without duplicating code and local resources, though this is a result of my solution's design rather than a fault with telerik's reporting platform. In retrospect, I should probably have added a "facade" layer (as they call it these days) to supply these services to the reports and the GUI projects. You may want to add a recommendation or a note in your "best practices" help topic for reports to this effect.
Also, I don't know about others, but I've the telerik report's method for binding data to charts counter-intuitive. I expected the chart I place on the report design surface to be available in the event handler for NeedDataSource, but it isn't because the Telerik.Reporting.Processing.Chart is made available instead. This makes it difficult to re-use the code for binding charts (and other elements as well). For example, it just so happens I have two charts on this report and it should be possible to use a single event handler to bind them both.
In any case, your answer did the trick, but I ended up saving the chart to a temporary image file and showing the image on the report instead of using the chart item.
I couldn't find any way to localize the chart without duplicating code and local resources, though this is a result of my solution's design rather than a fault with telerik's reporting platform. In retrospect, I should probably have added a "facade" layer (as they call it these days) to supply these services to the reports and the GUI projects. You may want to add a recommendation or a note in your "best practices" help topic for reports to this effect.
Also, I don't know about others, but I've the telerik report's method for binding data to charts counter-intuitive. I expected the chart I place on the report design surface to be available in the event handler for NeedDataSource, but it isn't because the Telerik.Reporting.Processing.Chart is made available instead. This makes it difficult to re-use the code for binding charts (and other elements as well). For example, it just so happens I have two charts on this report and it should be possible to use a single event handler to bind them both.
In any case, your answer did the trick, but I ended up saving the chart to a temporary image file and showing the image on the report instead of using the chart item.
0

shovavnik
Top achievements
Rank 1
answered on 08 May 2008, 07:51 AM
Thinking about this some more, I came up with a more constructive recommendation.
It would be very convenient if I could just pass a reference to an existing chart to a report and have the report display it as is. Never mind data binding, handling the NeedDataSource event, or custom logic on the report. The chart already exists (in this case): why not have the report clone it or even use the original reference?
It would be very convenient if I could just pass a reference to an existing chart to a report and have the report display it as is. Never mind data binding, handling the NeedDataSource event, or custom logic on the report. The chart already exists (in this case): why not have the report clone it or even use the original reference?
0
Hi shovavnik,
Thanks for the suggestions. We will consider them when improving the Reporting functionality.
The general purpose of the NeedDataSource event is only to specify the data for the current instance of the chart which is being processed at the moment (For more information please review the Report Life Cycle topic). Its appearance is configured at design time or at run time and by using the Chart report item, which is of type Telerik.Reporting.Chart. You can access it programmatically as shown in the sample code snippets or through the ItemDefinition property of the Processing.Chart object.
For your last suggestion I could recommend the following - instead of creating a temporary file, save the chart into a MemoryStream and then create an Image object from it. The Image object can be passed directly to the Value property of a PictureBox report item.
Best wishes,
Chavdar
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thanks for the suggestions. We will consider them when improving the Reporting functionality.
The general purpose of the NeedDataSource event is only to specify the data for the current instance of the chart which is being processed at the moment (For more information please review the Report Life Cycle topic). Its appearance is configured at design time or at run time and by using the Chart report item, which is of type Telerik.Reporting.Chart. You can access it programmatically as shown in the sample code snippets or through the ItemDefinition property of the Processing.Chart object.
For your last suggestion I could recommend the following - instead of creating a temporary file, save the chart into a MemoryStream and then create an Image object from it. The Image object can be passed directly to the Value property of a PictureBox report item.
Best wishes,
Chavdar
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

shovavnik
Top achievements
Rank 1
answered on 17 Aug 2008, 10:43 PM
Back in May, when we were discussing this issue, I followed your suggestion and passed an image of the chart to the report. I used the chart's Save method to save it to a temporary file instead of a MemoryStream, but it's the same idea.
The problem with this approach is that the dimensions for the report and the Windows Form are different and are both dynamic so they can't even be matched up. So the text is always stretched or squeezed and the chart doesn't look nearly as good in the report as it does on the form. In other words, a RadChart has to be used on the report for the report to work right.
Now that 2008 Q2 is out, I noticed that it has scantily documented SaveXml and LoadXml methods which are supposed to save the chart's state and load it later. However, I couldn't find the SaveXml and, more importantly, the LoadXml methods on either the Telerik.Reporting.Chart or Telerik.Reporting.Processing.Chart classes.
Now that the SaveXml and LoadXml are implemented, it seems so trivial to have it work right in the reports as well.
Does this feature exist elsewhere in the Reporting 2008 Q2 bundle?
If not, any chance it can be made available VERY SOON? (I don't mean to lay the pressure on you, but we're releasing a beta of product in about 10 days, and it would be VERY convenient to have this feature work right by then!)
The problem with this approach is that the dimensions for the report and the Windows Form are different and are both dynamic so they can't even be matched up. So the text is always stretched or squeezed and the chart doesn't look nearly as good in the report as it does on the form. In other words, a RadChart has to be used on the report for the report to work right.
Now that 2008 Q2 is out, I noticed that it has scantily documented SaveXml and LoadXml methods which are supposed to save the chart's state and load it later. However, I couldn't find the SaveXml and, more importantly, the LoadXml methods on either the Telerik.Reporting.Chart or Telerik.Reporting.Processing.Chart classes.
Now that the SaveXml and LoadXml are implemented, it seems so trivial to have it work right in the reports as well.
Does this feature exist elsewhere in the Reporting 2008 Q2 bundle?
If not, any chance it can be made available VERY SOON? (I don't mean to lay the pressure on you, but we're releasing a beta of product in about 10 days, and it would be VERY convenient to have this feature work right by then!)
0
Hi shovavnik,
Since Q1 2008 SP1 you can create and configure the Chart report item without the NeedDataSource event. You may consider this as an option and create the chart using the same methods as in the WinForms application.
Another possible way is to use a PictureBox item with the Sizing property set to AutoSize. This will resize the picture box item according to the size of the original picture without stretching or squeezing the image.
Unfortunately LoadXml/SaveXml methods between the Reporting Chart and the WinForms Chart are not applicable because they are actually different products although they look similar.
Sincerely yours,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Since Q1 2008 SP1 you can create and configure the Chart report item without the NeedDataSource event. You may consider this as an option and create the chart using the same methods as in the WinForms application.
Another possible way is to use a PictureBox item with the Sizing property set to AutoSize. This will resize the picture box item according to the size of the original picture without stretching or squeezing the image.
Unfortunately LoadXml/SaveXml methods between the Reporting Chart and the WinForms Chart are not applicable because they are actually different products although they look similar.
Sincerely yours,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

shovavnik
Top achievements
Rank 1
answered on 18 Aug 2008, 05:14 PM
I tried using the Sizing property. Unfortunately, that solution doesn't work because the specs call for a very strictly defined report layout. In other words, the chart needs to fill the prescribed borders as exactly as possible.
I remember reading somewhere (a few months ago) that the telerik reports actually used a WinForms chart internally (when viewed with a windows report viewer, I assume).
Is this not the way case? Is it really a separate implementation?
Anyway, regarding using the same method used by the WinForms application, I already explained way at the beginning of this thread that it will require too many changes in the code base to extract the chart generation AND LOCALIZATION facility to a separate facade assembly available to both the reports project and the winforms project.
What I'm trying to do is find a way to pass the chart data and appearance settings from the winforms project to the report, which should also speed up the report, since this report will always be called after the chart is already rendered on the winforms form.
Any ideas?
I remember reading somewhere (a few months ago) that the telerik reports actually used a WinForms chart internally (when viewed with a windows report viewer, I assume).
Is this not the way case? Is it really a separate implementation?
Anyway, regarding using the same method used by the WinForms application, I already explained way at the beginning of this thread that it will require too many changes in the code base to extract the chart generation AND LOCALIZATION facility to a separate facade assembly available to both the reports project and the winforms project.
What I'm trying to do is find a way to pass the chart data and appearance settings from the winforms project to the report, which should also speed up the report, since this report will always be called after the chart is already rendered on the winforms form.
Any ideas?
0
Hi shovavnik,
Because the charts are in different products they have different usages and are not completely interchangeable. For that reason the load/save xml methods between them are not quite applicable moreover the Reporting Chart item is not likely to need them for any core functionality.
You may consider generating chart images with different sizes from the WinForms application so that they can fit exactly the reserved space in the report definition. You can also set the PictureBox item size in pixels so that they will completely match. Hope this suggestion helps.
Regards,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Because the charts are in different products they have different usages and are not completely interchangeable. For that reason the load/save xml methods between them are not quite applicable moreover the Reporting Chart item is not likely to need them for any core functionality.
You may consider generating chart images with different sizes from the WinForms application so that they can fit exactly the reserved space in the report definition. You can also set the PictureBox item size in pixels so that they will completely match. Hope this suggestion helps.
Regards,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.