My problem is after I assigned data to report by calling report constructor, put it into report viewer and called dataBind() of report viewer. It should show my Pie chart and legend, but it only display the legend.
public PieChart(Dictionary<string, int> results, ArrayList percentageResult) |
{ |
InitializeComponent(); |
ChartSeries chartSeries = new ChartSeries(); |
chartSeries.Name = "Pie Chart"; |
chartSeries.Type = ChartSeriesType.Pie; |
int i = 0; |
foreach (KeyValuePair<string, int> item in results) |
{ |
List<Color> itemColor = new List<Color>(10); |
itemColor.Add(Color.Red); |
itemColor.Add(Color.Yellow); |
itemColor.Add(Color.Green); |
itemColor.Add(Color.Blue); |
itemColor.Add(Color.Brown); |
itemColor.Add(Color.Pink); |
itemColor.Add(Color.Orange); |
itemColor.Add(Color.Black); |
itemColor.Add(Color.Gray); |
itemColor.Add(Color.Olive); |
chartSeries.AddItem(item.Value, item.Key, itemColor[i]); |
chartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid; |
chart1.Legend.Items.Add(new LabelItem(item.Key + ": " + item.Value + ": " |
+ percentageResult[i] + " %")); |
chart1.Legend.Items[i].Marker.Appearance.FillStyle.MainColor = itemColor[i]; |
chart1.Legend.Items[i].Marker.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid; |
i++; |
} |
chartSeries.Appearance.LabelAppearance.Visible = false; |
chart1.Series.Add(chartSeries); |
chart1.Series[0].Appearance.TextAppearance.TextProperties.Font = |
new System.Drawing.Font(FontFamily.GenericSansSerif, 15); |
LabelItem labelItem = new LabelItem("chart"); |
chartSeries.AddItem(10, "a"); |
chartSeries.AddItem(20, "b"); |
chartSeries.AddItem(50, "c"); |
chartSeries.AddItem(100, "d"); |
chart1.Series.Add(chartSeries); |
detail.Items.AddRange(new ReportItemBase[] { chart1 }); |
} |
,above is report constructor source code,
PieChart pieChart = new PieChart(results, percentageResult); |
ReportViewer2.Report = pieChart; |
ReportViewer2.RefreshReport(); |
and this is my calling constructor source code part.
I also checked out the items in chart1, there are data.