在运行时启用/禁用图表系列 [英] Enable/Disable chart series at runtime

查看:75
本文介绍了在运行时启用/禁用图表系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以帮助解决MS Chart中的另一个问题。



我在我的图表中动态添加了五个系列,使用以下步骤: for循环:



I hope someone might be able to help with another question re MS Chart.

I have added five series dynamically to my chart, using the following procedure in a for loop:

private void addSeries(string nme, Color clr)
    {
        Chart1.Series.Add(nme);
        Chart1.Series[nme].Name = nme;
        Chart1.Series[nme].ChartType = SeriesChartType.Line;
        Chart1.Series[nme].BorderWidth = 2;
        Chart1.Series[nme].MarkerStyle = MarkerStyle.Circle;
        Chart1.Series[nme].XValueMember = "theDate";
        Chart1.Series[nme].YValueMembers = nme;
        Chart1.Series[nme].Legend = "Legend1";
        Chart1.Series[nme].Color = clr;
    }





现在,我希望能够通过点击按钮启用/禁用每个系列,但是当我尝试我收到一条错误消息,说明在SeriesCollection中找不到系列(永远不会超过循环中的第一个系列):在SeriesCollection中找不到名为MD的图表元素。我认为调用Series对象的Add方法会将命名的Series添加到SeriesCollection中。如何,我可以确保将动态创建的系列添加到集合中吗?



谢谢





Steve



Now, I want to be able to enable/disable each series via a button click, but when I try I''m getting an error message to the effect that the series (never gets past the first one in the loop) cannot be found in the SeriesCollection: "A chart element with the name MD could not be found in the SeriesCollection". I thought that calling the Add method of the Series object would add the named Series to the SeriesCollection. How, can I ensure that dynamically created series are added to the collection?

Thanks


Steve

推荐答案

使用启用属性系列(索引) )



见这里: http://stackoverflow.com/questions/15012718/selectively-hiding-series-in-ac-sharp-chart [ ^ ]



其他有趣的资源: http:// stackoverflow .com / questions / 1917707 / microsoft-chart-control-prevent-series-from-comingaring-in-legend [ ^ ]

http://blogs.msdn.com/b/alexgor/archive/2009/10/06/setting-chart- series-colors.aspx [ ^ ]

http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/caae5c06-f8a0-436c-8b39-865cf395d0ca/ [< a href =http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/caae5c06-f8a0-436c-8b39-865cf395d0ca/\"target =_ blanktitle =New Window> ^ ]

http:/ /msdn.microsoft.com/en-us/library/aa231230%28v=vs.60%29.aspx [ ^ ]
Use Enabled property for Series(index).

See here: http://stackoverflow.com/questions/15012718/selectively-hiding-series-in-a-c-sharp-chart[^]

Other interesting resources: http://stackoverflow.com/questions/1917707/microsoft-chart-control-prevent-series-from-appearing-in-legend[^]
http://blogs.msdn.com/b/alexgor/archive/2009/10/06/setting-chart-series-colors.aspx[^]
http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/caae5c06-f8a0-436c-8b39-865cf395d0ca/[^]
http://msdn.microsoft.com/en-us/library/aa231230%28v=vs.60%29.aspx[^]


这篇关于在运行时启用/禁用图表系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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