SeriesCollection

While working with Charting control in Windows forms. I found an issue in binding and rebinding the data into the chart control.

Here is the small piece of code to plot the data in a chart

string[] seriesArray = { "Semester1", "Semester2", "Semester3" };



int[] pointsArray = { Convert.ToInt32(0), Convert.ToInt32(semester[1]), Convert.ToInt32(semester[2]) };




this.chart1.Palette = ChartColorPalette.Berry;



this.chart1.Titles.Add("Growth of the Student");



for (int x = 0; x < seriesArray.Length; x++)


{




Series series = this.chart1.Series.Add(seriesArray[x]);


series.Points.Add(pointsArray[x]);


} 
  
  
While loading the data for the second time, i got an error "A chart element with the name already exists in the 'SeriesCollection'." The reason is, the chart is already having the series related data bound to it. 
  
Solution: 
  
chart1.Series.Clear(); 



chart2.Series.Clear();


chart3.Series.Clear();


this.chart1.Titles.Clear();


this.chart2.Titles.Clear();


this.chart3.Titles.Clear(); 
  
Cheers, 
Venkatesan prabu .J 
Head, KaaShiv InfoTech
Ebook Download
View all
Learn
View all