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

chart in subreport multiple times via collection

4 Answers 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 20 Dec 2011, 07:09 PM
It may be me, but I have a master report and in it I would like multiple sub reports that contain charts.

i created a report that works with the object model. Then I created a master repotr that contains this report (now a subreport) and sends it is List of the object model.
I do alot of settings of the chart programmatically in the detail report's "need data source" event.

However, the DataSource in the detail's "need data source" event is actually the whole collection and NOT an individual item from that collection.

I thought I had set it up in similar fashion as my grid data (does not use need data source event though), but I can't seem to figure out the trick to get it to work?

Does this make sense? Basically I a list of up to 4 objects. These objects contain info (title, points, etc.) necessary to construct a chart. I want the report to render 4 charts on my report.

any ideas?

thanks!

4 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 21 Dec 2011, 05:47 PM
Hello Robert,

The Report_NeedDataSource will get the whole List as data object, the DetailSection_NeedDataSource will be called once for every item in the list, the Chart_NeedDataSource event will be called, again, once for every item in the list. It depends on what you want to achieve. 

If we understand correctly you want to pass a List of 4 object to the detail Report and the detail Report should create 4 charts according to the list items. If that's the case you can use the Chart_NeedDataSource event. You can get the data object like this:

private void chart1_NeedDataSource(object sender, EventArgs e)
       {
           var chart = (Telerik.Reporting.Processing.Chart)sender;
           var report = (Telerik.Reporting.Processing.DetailSection)chart.Parent;

           //this will be the current item of the list
           var data = report.DataObject;
       }
Best wishes,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Robert
Top achievements
Rank 1
answered on 26 Dec 2011, 07:32 PM
I tried what you suggested. Was not able to get it to work.
There is no DetailSection.NeedDataSource event. The Chart_NeedDataSource event fired only once.  here is my code

public ReportDataChart(MyObjectModel om)
{
_om = om;
}
private void ReportDataChart_NeedDataSource(sender, e)
{
this.DataSource = _om.DataSeriesList // collection of 4 object models)
}
private void chart1_NeedDataSource(sender, e)
{
...telerik code in here from below
}





the report needDS fires once (as expected), but the chart only fires once. i have other code in the chart_NeeDS that formats the chart...like

chart1.DataSource =  ((DataSeriesDisplayViewModel)data.RawData).SeriesPoints;
chart1.ChartTitle.TextBlock.Text = "my great title";
etc.

Any advice?

0
Robert
Top achievements
Rank 1
answered on 26 Dec 2011, 07:39 PM
forgot to mention I get a report with 4 graphs, but it is only the first graph 4 times. It is not moving to the next item in the data list.
i kind of get it that once NeedDataSource is et, it no longer needs it and doesn't fire, but where does this code (chart formatting) need t ogo so that it fires 4x times, each time with an item in the colelction, and not the same item 4x?
0
Robert
Top achievements
Rank 1
answered on 26 Dec 2011, 07:53 PM
i put my code in the chart1_ItemDataBinding event and i got my charts (one for each item in the collection). i believe all is well and consider this discussion complete and closed to my satisfaction.

thanks!
Tags
General Discussions
Asked by
Robert
Top achievements
Rank 1
Answers by
Elian
Telerik team
Robert
Top achievements
Rank 1
Share this question
or