VB.NET使用CHART控件做实时曲线

VB.NET使⽤CHART控件做实时曲线
使⽤CHART 控件做实时曲线
编程,因⼀⼯程需要将现场数据采集过来,并以实时曲线的⽅式,显⽰出来,顾写了个例⼦程序,供⼤家参考,不对的地⽅请⼤家指正,谢谢!
废话不多说,下⾯是整个代码,希望能够帮到⼤家。
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
'//定义曲线1X轴变量为时间
Private X1(19) As String
'//定义曲线1Y轴变量为瞬时流量
Private Y1(19) As Double
'//定义曲线2X轴变量为时间
Private X2(19) As String
'//定义曲线2Y轴变量为瞬时流量
Private Y2(19) As Double
'//定义画图区域变量
Private fluxArea As ChartArea
'//定义Serial对象
Private fluxLine1 As Series
Private fluxLine2 As Series
'//定义Legends对象
Private fluxLegend As Legend
Private Sub InitChartSet()
'//初始化Chart对象设置
'//设置控件背景⾊
Chart1.BackColor = Color.Black
'//定义标题对象变量
Dim ChartTitle As New Title
'//设置Title信息
With ChartTitle
.Text = "⽪带秤流量实时曲线"
.Text = "⽪带秤流量实时曲线"
.ForeColor = Color.Yellow
.Font = New System.Drawing.Font("微软雅⿊", 16.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
End With
'//清除所有标题对象
Chart1.Titles.Clear()
Chart1.Titles.Add(ChartTitle)
'//清空画图区域
Chart1.ChartAreas.Clear()
'//创建chartarea对象实例
fluxArea = New ChartArea("fluxArea")
'//将定义的画图区域添加到chart
Chart1.ChartAreas.Add(fluxArea)
'//设置显⽰区域
With fluxArea
'//设置背景颜⾊为⿊⾊
.BackColor = Color.Black
'//设置X轴最⼩值
2008北京奥运会会徽
.AxisX.Minimum = 1
'//设置X轴最⼤值
.AxisX.Maximum = 20
'//设置X轴
.AxisX.Interval = 1wdm驱动
'//设置X轴标题
.AxisX.Title = "时间"
'//设置X轴标题字体
.AxisX.TitleFont = New System.Drawing.Font("微软雅⿊", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byt e))
盐酸芬氟拉明'//设置X轴线宽
.AxisX.LineWidth = 3
'//设置X轴颜⾊
.AxisX.LineColor = Color.Green
'//设置X轴线型
.AxisX.LineDashStyle = ChartDashStyle.Solid
'//设置X轴标题对齐
.AxisX.TitleAlignment = StringAlignment.Center
'//设置X轴标题颜⾊
.AxisX.TitleForeColor = Color.Yellow
'//设置X轴⽹格刻度线
.AxisX.MajorGrid.LineColor = Color.Green
'//设置X轴⽹格刻度线宽度
.AxisX.MajorGrid.LineWidth = 1
'//设置X轴⽹格刻度线样式
.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash
'//设置X轴刻度线颜⾊
.AxisX.MajorTickMark.LineColor = Color.Green
'//设置X轴刻度线长度
.AxisX.MajorTickMark.Size = 2
'//设置X轴刻度线宽度
.AxisX.MajorTickMark.LineWidth = 2
'//设置X轴刻度线样式
.AxisX.MajorTickMark.LineDashStyle = ChartDashStyle.Solid
'//设置X轴刻度线位置
.
AxisX.MajorTickMark.TickMarkStyle = TickMarkStyle.OutsideArea
'//设置X轴标签颜⾊
.AxisX.LabelStyle.ForeColor = Color.LawnGreen
'//设置Y轴最⼩值
.AxisY.Minimum = 0D
'//设置Y轴最⼤值
.AxisY.Maximum = 150D
.AxisY.Maximum = 150D
'//设置Y轴标题
.AxisY.Title = "⽪带秤瞬时流量"
'//设置Y轴标题字体
.
AxisY.TitleFont = New System.Drawing.Font("微软雅⿊", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byt e))
'//设置X轴线宽
.AxisY.LineWidth = 3
'//设置X轴颜⾊
.AxisY.LineColor = Color.Green
'//设置X轴线型
.AxisY.LineDashStyle = ChartDashStyle.Solid
'//设置Y轴标题对齐
.AxisY.TitleAlignment = StringAlignment.Center
'//设置Y轴标题颜⾊
.AxisY.TitleForeColor = Color.Yellow
'//设置Y轴⽹格刻度线
.AxisY.MajorGrid.LineColor = Color.Green
'//设置Y轴⽹格刻度线宽度
.AxisY.MajorGrid.LineWidth = 1
'//设置Y轴⽹格刻度线样式
.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash
'//设置X轴刻度线颜⾊
高中语文教学大纲
.AxisY.MajorTickMark.LineColor = Color.Green
'//设置X轴刻度线长度
.AxisY.MajorTickMark.Size = 2
'//设置X轴刻度线宽度
.
AxisY.MajorTickMark.LineWidth = 2
'//设置X轴刻度线样式
.AxisY.MajorTickMark.LineDashStyle = ChartDashStyle.Solid
'//设置X轴刻度线位置
.AxisY.MajorTickMark.TickMarkStyle = TickMarkStyle.OutsideArea
'//设置Y轴标签颜⾊
.AxisY.LabelStyle.ForeColor = Color.LawnGreen
End With
'//创建Legends对象实例
fluxLegend = New Legend("fluxLegend")
'//设置Legends对象
With fluxLegend
'//设置图例停靠位置为⾃动
.Position.Auto = True
'//设置图例对齐⽅式为居中
.Alignment = StringAlignment.Center
'//设置图例停靠位置为底部
.Docking = Docking.Bottom
'//设置图例的背景⾊为透明
.BackColor = Color.Transparent
'//设置图例的字体颜⾊为⽩⾊
.ForeColor = Color.White
'//设置图例字体
.Font = New System.Drawing.Font("微软雅⿊", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
End With
'//清除默认Legends
Chart1.Legends.Clear()
Chart1.Legends.Add(fluxLegend)
'//创建series对象实例
fluxLine1 = New Series("fluxLine1")
fluxLine2 = New Series("fluxLine2")
'//设置Serial对象1
With fluxLine1
With fluxLine1
'//设置线型
.ChartType = SeriesChartType.Spline
'//设置画线区域
.ChartArea = "fluxArea"
'//设置画线的宽度
.BorderWidth = 3
'//设置画线颜⾊
.Color = Color.LawnGreen
'//设置画线阴影
.ShadowOffset = 1
'//设置图⽰⽂字
.LegendText = "4A路⽪带秤"
'//设置图例属性
.Legend = "fluxLegend"
End With
留几本书在窗台 阅读答案
'//设置Serial对象2
With fluxLine2
'//设置线型
.ChartType = SeriesChartType.Spline
'//设置画线区域
.ChartArea = "fluxArea"
'//设置画线的宽度
.BorderWidth = 3
'//设置画线颜⾊
.Color = Color.Red
'//设置画线阴影
.ShadowOffset = 1
'//设置图⽰⽂字
.LegendText = "4B路⽪带秤"
'//设置图例属性
.Legend = "fluxLegend"
End With
'//清除默认series
Chart1.Series.Clear()
'//将定义好的曲线对象添加到chart
Chart1.Series.Add(fluxLine1)
Chart1.Series.Add(fluxLine2)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'//
InitChartSet()
End Sub
Private Sub InitChartData()
'// 设置初始数据
Dim i As Integer = 0
For i = 0 To 19
X1(i) = Format(Now(), "HH:mm:ss")
X2(i) = Format(Now(), "HH:mm:ss")
Y1(i) = 0
Y2(i) = 0
Next
'//显⽰数据
Chart1.Series("fluxLine1").Points.DataBindXY(X1, Y1)
Chart1.Series("fluxLine2").Points.DataBindXY(X2, Y2)
End Sub
皮里村蹲点日记Private Sub RefreshChartData()
'// 更新曲线数据
Dim i As Integer
For i = 0 To 18
X1(i) = X1(i + 1)
X2(i) = X2(i + 1)
Y1(i) = Y1(i + 1)
Y2(i) = Y2(i + 1)
Next
Y1(19) = Math.Round(100 * Rnd(100) * 1.0264, 2)
X1(19) = Format(Now(), "HH:mm:ss")
Y2(19) = Math.Round(100 * Rnd(100) * 1.0264, 2)
X2(19) = Format(Now(), "HH:mm:ss")
Chart1.Series("fluxLine1").Points.DataBindXY(X1, Y1)
Chart1.Series("fluxLine2").Points.DataBindXY(X2, Y2)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click        InitChartData()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick        RefreshChartData()
End Sub
End Class

本文发布于:2024-09-21 01:35:13,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/415738.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:设置   刻度   对象   曲线   定义   图例   变量
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议