C# 图表系列清除不工作

C# 图表系列清除不工作,c#,winforms,charts,series,C#,Winforms,Charts,Series,我需要在我的C#应用程序中多次调用CreateChart()。但是一个错误说 其他信息:“SeriesCollection”中已存在名为“Income”的图表元素 我使用下面的代码清除了图表系列 foreach (var series in chart1.Series) { series.Points.Clear(); } 从中获取上述代码 但同样的问题也出现了。这是CreateChart()。它第一次加载图表时没有出现问题。如果我多次加载它,就会发生错误 fo

我需要在我的C#应用程序中多次调用CreateChart()。但是一个错误说

其他信息:“SeriesCollection”中已存在名为“Income”的图表元素


我使用下面的代码清除了图表系列

foreach (var series in chart1.Series)
    {
        series.Points.Clear();
    }
从中获取上述代码

但同样的问题也出现了。这是CreateChart()。它第一次加载图表时没有出现问题。如果我多次加载它,就会发生错误

foreach (var series in chart1.Series)
                {
                    series.Points.Clear();
                }
                chart1.Series[0].IsVisibleInLegend = false;
                var IncSeries = new Series("Income");
                var ExpSeries = new Series("Expense");
                IncSeries.Points.DataBindXY(new[] { "Today's Income" }, new[] { Income });
                ExpSeries.Points.DataBindXY(new[] { "Today's Expense" }, new[] { Expense });
                chart1.ChartAreas[0].AxisX.IsReversed = true;
                chart1.Series.Add(IncSeries);
                chart1.Series.Add(ExpSeries);

你还没有清除序列号。您只清除了系列中的点

chart1.Series.Clear();
var IncSeries = new Series("Income");
var ExpSeries = new Series("Expense");
IncSeries.Points.DataBindXY(new[] { "Today's Income" }, new[] { Income });
            ExpSeries.Points.DataBindXY(new[] { "Today's Expense" }, new[] { Expense });
chart1.ChartAreas[0].AxisX.IsReversed = true;
chart1.Series.Add(IncSeries);
chart1.Series.Add(ExpSeries);
chart1.Series[0].IsVisibleInLegend = false;

你还没有清除序列号。您只清除了系列中的点

chart1.Series.Clear();
var IncSeries = new Series("Income");
var ExpSeries = new Series("Expense");
IncSeries.Points.DataBindXY(new[] { "Today's Income" }, new[] { Income });
            ExpSeries.Points.DataBindXY(new[] { "Today's Expense" }, new[] { Expense });
chart1.ChartAreas[0].AxisX.IsReversed = true;
chart1.Series.Add(IncSeries);
chart1.Series.Add(ExpSeries);
chart1.Series[0].IsVisibleInLegend = false;

“我使用下面的代码清除了图表系列”-不,该代码清除了图表系列集合中每个系列的点集合。与其只是寻找要复制的代码,不如尝试理解它。一旦您了解了基本的工作原理,您就可以从中构建,而无需找到要复制的代码。“我使用下面的代码片段清除了图表系列”-不,该代码清除了图表系列集合中每个系列的点集合。与其只是寻找要复制的代码,不如尝试理解它。一旦您了解了基本的东西是如何工作的,您就可以从那里构建,而无需找到要复制的代码。