Chart控件绘制实时折线图表——Spline
Posted yunchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Chart控件绘制实时折线图表——Spline相关的知识,希望对你有一定的参考价值。
1、首先,将chart控件添加到窗口。
2、设置chart - series 主要t属性:
2.1 IsXValueIndexed = true;
2.2 XValueType = Time;
3、编写初始化函数:
Private Sub InitChart() Dim r As Random = New Random() Dim series As Series = Chart1.Series(0) Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "HH:mm" Chart1.ChartAreas(0).AxisX.ScaleView.Size = 5 series.ChartType = SeriesChartType.Spline; Chart1.ChartAreas(0).AxisX.ScrollBar.IsPositionedInside = True Chart1.ChartAreas(0).AxisX.ScrollBar.Enabled = True series.Points.AddXY(DateTime.Now.ToString("HH:mm"), r.Next(1, 100)) If DateTime.Now.Second = 0 Then ‘因定时器与当前时间不准确,故判断当前时间秒数是否为0 Timer1.Interval = 1000 * 60 Else Timer1.Interval = 1000 * (60 - DateTime.Now.Second) End If Timer1.Start() End Sub
4.编写Time函数:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Timer1.Stop() ‘Chart1.Series(0).Points.Clear() ‘每次清除上一次绘制的数据 Dim random As Random = New Random() Dim series As Series = Chart1.Series(0) series.Points.AddXY(DateTime.Now, random.Next(1, 20)) If DateTime.Now.Second = 0 Then ‘初始化定时器 Timer1.Interval = 1000 * 60 End If Timer1.Start() End Sub
5:在From_Load事件调用InitChart()方法
以上,借鉴博客
以上是关于Chart控件绘制实时折线图表——Spline的主要内容,如果未能解决你的问题,请参考以下文章
Visual Studio 2010中,采用chart插件绘制图表,怎样将背景中的网格线去掉呢?具体操作能详细叙述一下吗?