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

2 posts, 0 answers
  1. binny
    binny avatar
    21 posts
    Member since:
    Jan 2015

    Posted 13 Apr 2016 Link to this post

    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!

                   

     

     

     

     

     

  2. binny
    binny avatar
    21 posts
    Member since:
    Jan 2015

    Posted 14 Apr 2016 in reply to binny Link to this post

    Figured it out, had to clean the previous plot area ... Thanks
Back to Top