问题描述
我有很多图表,是否可以循环初始化/设置数据?现在我有
chart1.series [0] .points.clear()
chart1.series [1] .points .clear ()
等多个系列和多个图表。我喜欢循环,但我似乎无法使用循环设置文本
chart(i).series [i] .points.clear( )
i只是出错了。我也试过下面的循环,虽然没有错误但没有任何反应
图表位于分割面板中可能很重要标签。所以14个标签每个标签有两个图表。
谢谢
我有什么试过:
i have a lot of charts, is it possible to loop through to initialise / set data? right now i have
chart1.series[0].points.clear()
chart1.series[1].points.clear()
etc. for multiple series and multiple charts. i'd love to loop through but i can't seem to set the text using a loop
chart(i).series[i].points.clear()
i just get an error. i've also tried the loop below, and whilst i get no errors, nothing happens
it probably matters that the charts are located in split panels, which are located in tabs. so there are two charts per tab for 14 tabs.
thanks
What I have tried:
foreach (Chart x in this.Controls.OfType<chart>())
{
x.ChartAreas[0].series[0].clear
x.ChartAreas[0].series[1].clear
....
}
推荐答案
foreach (Chart x in this.Controls.OfType(Chart)) {
foreach (ChartArea area in x.ChartAreas) {
foreach (Series series in area.Series){
area.series.Points.Clear();
// Add new points here
}
}
}
您应该添加以确保ChartAreas和Series集合不为空!
You should add to ensure that the ChartAreas and Series collections are not null!
这篇关于循环图表以初始化/设置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!