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

Pie Chart doesn't display

1 Answer 129 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pakorn
Top achievements
Rank 1
Pakorn asked on 27 Mar 2010, 07:00 AM

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.
 

1 Answer, 1 is accepted

Sort by
0
Pakorn
Top achievements
Rank 1
answered on 31 Mar 2010, 04:21 AM
Any suggestion? I'm still waiting for your help.

I found that if I do only that, datasource will be null and that might be the cause of problem. So I directly assigned data to datasource of chart object, the chart show up. But I can't do in this way because I need to customize something such as Color, Label of items by using ChartSeries object. So do you have any suggestion?
Tags
General Discussions
Asked by
Pakorn
Top achievements
Rank 1
Answers by
Pakorn
Top achievements
Rank 1
Share this question
or