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

Need to render the pie chart horizontally (six pie charts per page)

3 Answers 128 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Karthikeyan
Top achievements
Rank 1
Karthikeyan asked on 09 Jan 2013, 12:23 PM

Plotting Pie chart issue:

Data Structure: QuestionID, QuestionName, Answer, ResponseCount

Requirement : Need to plot six pie charts per page (Horizontally 3 per line)

Problem Statement: We are getting the pie chart plotted in vertical and not in horizontal

Solution tried:

We need to plot a pie chart based on the Answer and responsecount. We tried this below option of plotting the chart in the groupheadersection of the report.
 
Chart Title: Question Name
Chart series Item Y Value : ResponseCount
Chart series Item Name : Answer

GroupHeaderSection ItemDataBinding :

In this, we are getting the datatable from the report datasource and binding it to the chart. The piecharts are rendered correctly but getting only 3 pie charts per page in vertical.

We are tried this option based on the below link:

http://www.telerik.com/community/forums/reporting/telerik-reporting/graph-for-each-group.aspx

Note:
We have attached the datastructure in the spreadsheet,generated pie charts (refer image).

Expected Output:
6 Pie charts per page (3 pie charts per line horizontally)

private void groupHeaderSection2_ItemDataBinding(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.GroupSection groupHeaderSection = (Telerik.Reporting.Processing.GroupSection)sender;
            Telerik.Reporting.Processing.Report report = groupHeaderSection.Report;
            var group = groupHeaderSection.DataObject["QuestionID"];
            DataTable table = (DataTable)report.DataSource;
            DataRow[] rows = table.Select(string.Format(CultureInfo.InvariantCulture, "QuestionID={0}", group), "ResponseCount DESC");
  
            Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)groupHeaderSection.ChildElements.Find("Chart1", true)[0];
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition;
  
            chartDef.IntelligentLabelsEnabled = false;
  
            Telerik.Reporting.Charting.ChartSeries chartSeries = new Telerik.Reporting.Charting.ChartSeries();
            chartDef.Series.Clear();
            chartSeries.Type = Telerik.Reporting.Charting.ChartSeriesType.Pie;
            chartSeries.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
            chartDef.Legend.TextBlock.Visible = true;
            chartSeries.Appearance.ShowLabelConnectors = true;
            chartSeries.Appearance.StartAngle = 270;
  
            Telerik.Reporting.Charting.Styles.ChartMargins chartMargins2 = new Telerik.Reporting.Charting.Styles.ChartMargins();
  
            chartMargins2.Bottom = new Telerik.Reporting.Charting.Styles.Unit(20D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins2.Top = new Telerik.Reporting.Charting.Styles.Unit(5D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins2.Right = new Telerik.Reporting.Charting.Styles.Unit(5D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins2.Left = new Telerik.Reporting.Charting.Styles.Unit(5D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
  
            chartDef.PlotArea.Appearance.Dimensions.Margins = chartMargins2;
  
            foreach (var row in rows)
            {
                chartDef.ChartTitle.TextBlock.Text = row["Description"].ToString();
                ChartSeriesItem item = new ChartSeriesItem();
                item.YValue = Convert.ToDouble(row["ResponseCount"]);
                item.Name = row["Value"].ToString();
                item.Appearance.Exploded = true;
                item.Appearance.FillStyle.FillType = FillType.Solid;
  
                item.Label.TextBlock.Text = row["Value"].ToString() + " - #%";
                chartSeries.Items.Add(item);
            }
            chartDef.Series.Clear();
            chartDef.Series.Add(chartSeries);
            
            chartDef.SeriesOrientation = ChartSeriesOrientation.Horizontal;
  
   
        }

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 14 Jan 2013, 08:55 AM
Hello Karthikeyan,

The result of your approach is a pie chart item rendered for each group on a page as described in this help article: Understanding Report Structure. If you want to generate items horizontally you can use SubReport items and order as many fit properly on a line into the page. Each subReport item will contain a pie chart, and its data will be a filtered subset of the original data.

I hope this helps.

Regards,
Stef
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Karthikeyan
Top achievements
Rank 1
answered on 16 Jan 2013, 12:58 PM

We tried to plot the graph using subreport but the report is generated for every line item in the subreport and not for the question group like 10,11,.. in the attached datastructure . Also the question groups will grow dynamically. Please let us know how to plot the filtered subset in the subreport piechart so that 6 pie charts can be plotted in the page.

We are expecting the result as per the attached image.

For eg: If we have 12 questions , it should span across 2 pages with 6 pie per page.
0
Stef
Telerik team
answered on 21 Jan 2013, 03:04 PM
Hello Karthikeyan,

In order to change the grouping behavior additional criteria is needed. Please, check the settings in the attached sample.report. It illustrates How-To: Creating Master-Detail Reports Using SubReports, where the subreport item contains a pie chart report. The whole data is passed to the subreport, this data will be filtered on parent level - notice the additional column about the page group pointing where certain data to appear. In the master report there is a grouping based on Pagegroup column and subreport item in the group. PageBreak of the detail section is used in order to have one sub report per page.

I hope this helps.

Kind regards,
Stef
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
Karthikeyan
Top achievements
Rank 1
Answers by
Stef
Telerik team
Karthikeyan
Top achievements
Rank 1
Share this question
or