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

Pie Chart with autorefresh creating the multiple item names each time it refreshes

1 Answer 27 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
binny
Top achievements
Rank 1
binny asked on 13 Apr 2016, 09:35 PM

Hello,

I am creating a pie chart with three items

Responded/ Responded with comments/ Not responded

                 DataTable dt = GetDataTable();

                PieSeries chartData = new PieSeries();
                PieChart1.ChartTitle.Text = "Title";
                chartData.StartAngle = 90;
                chartData.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.PieAndDonutLabelsPosition.Center;

                SeriesItem item = new SeriesItem();
                SeriesItem item1 = new SeriesItem();
                SeriesItem item2 = new SeriesItem();

                foreach (DataRow row in dt.Rows)
                {

                    if (row["Responded"] != null && Convert.ToBoolean(row["Responded"]))
                    {
                        i++;
                    }

                    else if (row["Respondedwithcomments"] != null && Convert.ToBoolean(row["Respondedwithcomments"]))
                    {
                        j++;
                    }

                    else if(row["Responded"] == null)
                    {
                        k++;
                    }
                }

                chartData.LabelsAppearance.DataFormatString = "{0}";
                chartData.TooltipsAppearance.DataFormatString = "{0} ";
               
                
                item.Name = "Responded"; 

                item.YValue = i;

                item.BackgroundColor = System.Drawing.Color.YellowGreen;

             
                item1.Name = "Responded with comments";              
                item1.YValue = j;               
                item1.BackgroundColor = System.Drawing.Color.PaleVioletRed;
                

                item2.Name = "Not Responded";               
                item2.YValue = k;            
                item2.BackgroundColor = System.Drawing.Color.LightYellow;


              chartData.Items.Add(item);
                chartData.Items.Add(item1);
                chartData.Items.Add(item2);
               
              

                PieChart1.PlotArea.Series.Add(chartData);

 

Each time the chart refreshes to get the new data , the series name adds up so and I am also not sure that I am doing it the right way , please help!

               

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
binny
Top achievements
Rank 1
answered on 14 Apr 2016, 06:54 PM
Figured it out, had to clean the previous plot area ... Thanks
Tags
Chart (HTML5)
Asked by
binny
Top achievements
Rank 1
Answers by
binny
Top achievements
Rank 1
Share this question
or