循环图表以初始化/设置数据? [英] Loop through charts to initialise / set data?

查看:71
本文介绍了循环图表以初始化/设置数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多图表,是否可以循环初始化/设置数据?现在我有



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
                ....
            }

推荐答案

执行Chart [i]时出现错误的问题.Series [i] .Points.Clear()很可能是由于使用图表和系列的相同迭代器。只有每个图表和系列的数量相同时,这才会有效。



此外,发布的循环只清除点,你调试通过以确保它进入循环吗?



因此,当我假设您提供的循环时循环选项卡时,您将需要2个额外的/ foreach循环。



您的循环将迭代找到每个Chart控件。

然后一个循环将迭代Chart循环中的每个ChartArea,第二个循环应迭代ChartArea循环中的每个Series.



An issue causing the error when you did the Chart[i].Series[i].Points.Clear() is most likely caused by using the same iterator for Chart and Series. This would only ever work if you had the same number of each Chart and Series.

Also the loop posted only clears points, have you debugged through to ensure it is getting inside the loop?

So while looping through the tabs as I'm assuming the loop you provided does, you will need 2 additional for/foreach loops.

Your loop will iterate each Chart control found.
Then one loop will iterate each ChartArea within the Chart loop, and the second should iterate each Series within the ChartArea loop.

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!


这篇关于循环图表以初始化/设置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆