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;
}