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

Binding Chart inside detail section

5 Answers 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sivam
Top achievements
Rank 1
Sivam asked on 25 May 2010, 11:55 AM
Hi,

   I'm having chart in detail section. I need to bind the chart based on the item value of the report. I directly bind the chart in the detail_ItemDataBound without NeedDataSource event for the chart. I didn't get the chart. Then i try adding NeedDataSource event for the chart. But this gets executed before detail_ItemDataBound. Again I didn't get the chart. Then i tried detail_ItemDataBinding event to get value. Later i use the function for binding chart which i call in detail_ItemDataBound or in detail_ItemDataBinding. Still i didn't get the chart. All i get is there is no or empty series.

How can i bind the chart which is in detail section?

Here is the code which i use the bind the chart. Assume dt is DataTable holding data.
if (dt.Rows.Count > 0)
                {

                    for (int i = 0; i < dt.Rows.Count; i++)
                        total += Convert.ToInt32(dt.Rows[i]["Cnt"]);

                    Telerik.Reporting.Processing.Chart chtCur = sender as Telerik.Reporting.Processing.Chart;
                   
                    this.chtCur.Series.Clear();
                    this.chtCur.ChartTitle.TextBlock.Text = "Factors";
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Telerik.Reporting.Charting.ChartSeries chartseries = new Telerik.Reporting.Charting.ChartSeries();
                        Telerik.Reporting.Charting.ChartSeriesItem item = new Telerik.Reporting.Charting.ChartSeriesItem();
                        item.Label.TextBlock.Text = dt.Rows[i]["Val"].ToString() + "\n" + (Convert.ToInt32(dt.Rows[i]["Cnt"]) / total * 100).ToString() + "%";
                        item.Name = dt.Rows[i]["Val"].ToString();
                        item.YValue = Convert.ToInt32(dt.Rows[i]["Cnt"]) / total * 100;
                        chartseries.Type = Telerik.Reporting.Charting.ChartSeriesType.Pie;
                        chartseries.Name = dt.Rows[i]["Val"].ToString();
                        chartseries.Items.Add(item);
                        this.chtCur.Series.Add(chartseries);
                    }
                    pnlCur.Visible = true;
                }
                else
                    pnlCur.Visible = false;

Please help.
Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 May 2010, 12:22 PM
Hello Sivam,

You can do this entirely through the Report Designer by binding the chart through its DataSource property and then if needed you can filter the it based on the report parameters or field from the report data source. This is the approach used in the Product Line Sales demo report - open the Visual Studio examples and review its implementation carefully.

All the best,
Steve
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sivam
Top achievements
Rank 1
answered on 30 May 2010, 11:20 AM
Thanks for the response. How to specify the field from report datasource in the filter?
0
Steve
Telerik team
answered on 31 May 2010, 05:04 PM
Hello Sivam,

You can filter the chart datasource based on the main report's datasource by using its Filter property and as expression =ReportItem.Parent.DataObject. From here on, you can be more concrete and define the exact field you would filter upon like so:

=ReportItem.Parent.DataObject.IDFieldFromReport

or based on your own conditions (e.g. report parameters).

Sincerely yours,
Steve
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
HenSys
Top achievements
Rank 1
answered on 31 May 2010, 07:56 PM
That VS example (as well as my test report) do not show series in the wizard when binding with the report designer. As yet, I haven't been able to product anything with the chart, though when executed through the query builder, the datasource returns results. I am currently working with the trial version.  Any thoughts?
0
Steve
Telerik team
answered on 01 Jun 2010, 05:19 PM
Hi Brandon,

Chart series are automatically generated in runtime, when the chart is bound through the designer. If you want to specify fields that are used for the YAxis, you would have to create a serie manually and specify the DataYColumn you desire. This is what has been done in the Product Line Sales example, which you refer to.

Sincerely yours,
Steve
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Sivam
Top achievements
Rank 1
Answers by
Steve
Telerik team
Sivam
Top achievements
Rank 1
HenSys
Top achievements
Rank 1
Share this question
or