C# Microsoft Chart Controls/Dundas Charts 清除内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1098131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 08:10:42  来源:igfitidea点击:

Microsoft Chart Controls/Dundas Charts Clear Contents?

c#.netmicrosoft-chart-controlsdundas

提问by Goober

I am using the Dundas Chart Controls and Microsoft Chart Controls for .NET. Currently I have a method which populates the chart control with a date from a generic List.

我正在使用 Dundas Chart Controls 和 Microsoft Chart Controls for .NET。目前我有一种方法可以用通用列表中的日期填充图表控件。

Let's say that I populate the chart with data from one list. Then I want to populate the chart with data from another list.

假设我使用一个列表中的数据填充图表。然后我想用另一个列表中的数据填充图表。

I have a problem populating the chart with the data from the second list. I end up with a chart that displays the combined data from list 1 and list 2, whereas I want it to display only the data from the first list, and then clear the chart before displaying the data from the second list.

我在用第二个列表中的数据填充图表时遇到问题。我最终得到一个显示列表 1 和列表 2 中合并数据的图表,而我希望它只显示第一个列表中的数据,然后在显示第二个列表中的数据之前清除图表。

I have tried various method calls to clear the chart control before populating it with the data from the second list but to no avail.

在用第二个列表中的数据填充图表控件之前,我尝试了各种方法调用来清除图表控件,但无济于事。

Is there a way of doing this?

有没有办法做到这一点?

采纳答案by Goober

I found it! Do this:

我找到了!做这个:

chart1.Series[0].Points.Clear();

回答by casperOne

You should probably post some example code.

您可能应该发布一些示例代码。

However, I would guess it is simply a matter of resetting the data source. Assuming you have a list of points (or some other structure), you should probably create a new instance of that data container (i.e. the list), populate that, and then assign it to the chart.

但是,我想这只是重置数据源的问题。假设您有一个点列表(或一些其他结构),您可能应该创建该数据容器(即列表)的新实例,填充它,然后将其分配给图表。

Instead, it seems like you are probably trying to set the elements of an existing data container and not clearing it out correctly.

相反,您似乎正在尝试设置现有数据容器的元素,但没有正确清除它。

回答by John M

A comment for others who may come across this:

对可能遇到此问题的其他人的评论:

To clear out the chart series, titles, and legends:

清除图表系列、标题和图例:

//clear chart
Chart1.Series.Clear();
Chart1.Titles.Clear();
Chart1.Legends.Clear();           
//create chart