C# Chart中数据更新

浩洁 2014-05-10 08:09:40
刚接触这个控件,目前我在设计时手动添加好了DataPoint,可以直接看到效果
在程序中用Timer控件循环更新里面的值,但是控件没有变化,还需要加上什么代码?

private void Timer_Tick(object sender, EventArgs e)
{
this.ShowChart6();
}

private void ShowChart6()
{
for (int groupIndex = 0; groupIndex < 12; groupIndex++)
{
this.chart6.Series[0].Points[groupIndex].AxisLabel = this.CountList.Groups[groupIndex].Header;
this.chart6.Series[0].Points[groupIndex].YValues[0] = Double.Parse(this.CountList.Groups[groupIndex].Items[0].SubItems[1].Text);
this.chart6.Series[1].Points[groupIndex].YValues[0] = Double.Parse(this.CountList.Groups[groupIndex].Items[1].SubItems[1].Text);
this.chart6.Series[2].Points[groupIndex].YValues[0] = Double.Parse(this.CountList.Groups[groupIndex].Items[2].SubItems[1].Text);
}
}
...全文
1211 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
浩洁 2014-05-13
  • 打赏
  • 举报
回复
引用 7 楼 wind_cloud2011 的回复:
我之前是
this.timer.Interval = 500;
this.timer.Enabled = true;
我不知道改成200000有什么不一样?没有试,我现在用的是4楼的办法,重新加。
但是遇到一个问题,就是在其他电脑上不能用,出现一个错误。如我另外一个帖子所述http://bbs.csdn.net/topics/390785694
现在我的解决方案是修改引用的设置,如图,不知道有没有更好的办法?
wind_cloud2011 2014-05-11
  • 打赏
  • 举报
回复
这个放在load里吧,这样试试 this.timer.Interval = 20000; this.timer.Enabled = true;  if (updateWinform) {   this.ShowChart6(); updateWinform = false; this.timer.Enabled = false; }
浩洁 2014-05-10
  • 打赏
  • 举报
回复
引用 5 楼 wind_cloud2011 的回复:
如果直接调用 ShowChart6()正常,那放在timer里也应该正常,你timer的Interval设置为多少
开始是500,

        private void timer_Tick(object sender, EventArgs e)
        {
            if (updateWinform)
            {
                updateWinform = false;
                this.timer.Enabled = false;
                this.ShowChart6();
                this.timer.Interval = 20000;
                this.timer.Enabled = true;
            }
        }
wind_cloud2011 2014-05-10
  • 打赏
  • 举报
回复
如果直接调用 ShowChart6()正常,那放在timer里也应该正常,你timer的Interval设置为多少
浩洁 2014-05-10
  • 打赏
  • 举报
回复
引用 2 楼 wind_cloud2011 的回复:
Timer控件是不是没有启动
引用 3 楼 caozhy 的回复:
Timer的Interval、Enabled属性怎么设置的,Tick事件有没有关联给Timer_Tick
这个Timer控件都没有问题,我调试到那里了,值都已经赋给了Chart的Points,但是图就是不更新,现在的解决方法还是要重新添加点,不能给原来的点重新赋值,如下:
        private void ShowChart6()
        {
            this.chart6.Series[0].Points.Clear();
            this.chart6.Series[1].Points.Clear();
            this.chart6.Series[2].Points.Clear();
            for (int groupIndex = 0; groupIndex < 12; groupIndex++)
            {
                DataPoint dPoint1 = new DataPoint(0, Convert.ToDouble(this.CountList.Groups[groupIndex].Items[0].SubItems[1].Text));
                dPoint1.AxisLabel = this.CountList.Groups[groupIndex].Header;
                DataPoint dPoint2 = new DataPoint(0, Convert.ToDouble(this.CountList.Groups[groupIndex].Items[1].SubItems[1].Text)); 
                DataPoint dPoint3 = new DataPoint(0, Convert.ToDouble(this.CountList.Groups[groupIndex].Items[2].SubItems[1].Text));
                this.chart6.Series[0].Points.Add(dPoint1);
                this.chart6.Series[1].Points.Add(dPoint2);
                this.chart6.Series[2].Points.Add(dPoint3);
            }
        }
threenewbee 2014-05-10
  • 打赏
  • 举报
回复
Timer的Interval、Enabled属性怎么设置的,Tick事件有没有关联给Timer_Tick
wind_cloud2011 2014-05-10
  • 打赏
  • 举报
回复
Timer控件是不是没有启动
浩洁 2014-05-10
  • 打赏
  • 举报
回复
很奇怪的问题是:里面数据确实是更新过来了,为什么将this.ShowChart6();这一句放在窗体的Load事件里就能够正确?而放在时间那个里面的时候就不能更新控件?

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧