A chart element already exists in seriescollection

Answered A chart element already exists in seriescollection

  • 29 Juni 2009 11:41
     
     
    Hi All,

    I am using VS2008 to generate multi series graphs. I am getting error "A chart element already exists in seriescollection". The dataset which i am getting from database is like this

    Period    MinET    MeanET    MaxET
    ====    ====   =====    =====
    Latest      19         545         12345
    Previous    20         542          23644
    Last1week 19        234         365478
    ========================
    My Code is like this:

     

    foreach (DataRow row in dsAll.Tables[0].Rows)

    {

     

    string seriesName1 = row["MinEt"].ToString();

     

    string seriesName2 = row["MeanEt"].ToString();

     

    string seriesName3 = row["MaxEt"].ToString();

    Chart1.Series.Add(seriesName1);

    Chart1.Series.Add(seriesName2);

    Chart1.Series.Add(seriesName3);

    Chart1.Series[seriesName1].ChartType = System.Web.UI.DataVisualization.Charting.

    SeriesChartType.Line;

    Chart1.Series[seriesName1].BorderWidth = 2;

    Chart1.Series[seriesName2].ChartType = System.Web.UI.DataVisualization.Charting.

    SeriesChartType.Line;

    Chart1.Series[seriesName2].BorderWidth = 2;

    Chart1.Series[seriesName3].ChartType = System.Web.UI.DataVisualization.Charting.

    SeriesChartType.Line;

    Chart1.Series[seriesName3].BorderWidth = 2;

     

     

    for (int colIndex = 2; colIndex < dsAll.Tables[0].Columns.Count; colIndex++)

    {

     

    string columnName = dsAll.Tables[0].Columns[colIndex].ColumnName;

     

    int YVal = (int)row[columnName];

    Chart1.Series[seriesName1].Points.AddXY(columnName, YVal);

    }

    }
    It is throwing error "A chart element with the name '19' already exists in the 'SeriesCollection'".

    If anybody knows solution to this please help me.

    Thanks in Advance,
    Sarat Chandra




Semua Balasan

  • 29 Juni 2009 15:21
    Pemilik
     
     Jawab
    This means that you are trying to add the series with the name which already exsists in the collection. Series names need to be unique.

    Alex.
    http://blogs.msdn.com/alexgor
  • 30 Juni 2009 4:40
     
     
    Hi,

    I am creating three different series with different names. Still it is giving same problem(refer the code above). If anyone know the solution about this ..please help me..

    Thanks in advance..
    Sarat Chandra
  • 08 Juli 2009 1:47
    Pemilik
     
     
    In your code you create Series with name "MinEt" multiple times in the loop of data rows.

    Alex.
    http://blogs.msdn.com/alexgor
  • 22 Juli 2012 20:58
     
     
    different but you refer them maybe several times in your code, so use series.clear...