如何把实时数据在VB中用曲线图显示
5个回答
推荐于2016-04-06 · 知道合伙人软件行家
关注
展开全部
VB可通过Timer控件的Timer事件中使用Line方法或PSet 方法绘制线条、色彩实现实时显示采集数据的曲线。
Line方法,在对象上画直线和矩形。
PSet 方法,将对象上的点设置为指定颜色。
以下是一段工控程序的使用Line方法的代码:
Option Explicit
Dim quitflag As Boolean
Dim cmdXianshiFlag As Boolean
Dim cmdTestFlag As Boolean
Dim p As Integer
Dim h As Integer
Dim miao1 As Integer
Dim fen1 As Integer
Dim j As Integer
Dim ii As Integer
Private br_br As Double
Private ab_bm As Double
Private wy_wy As Double
Private shijian(360) As String * 10
Private shijian_zh(360) As String * 10
Private record_zh(5, 360) As Single
Private record(5, 360) As Single
Private c(360) As Variant
Const a = 3.141592654 * 2
Public Function xp(colvb As Variant, xx As Variant, yy As Variant, txt As Variant)
Picture1.ForeColor = colvb 'QBColor(14)
Picture1.CurrentX = xx
Picture1.CurrentY = yy
Picture1.Print txt '
End Function
Private Sub CmdTest_Click()
If cmdTestFlag Then
For j = 0 To 359
record(0, j) = 0
record(1, j) = 0
record(2, j) = 0
record(3, j) = 0
record(4, j) = 0
record(5, j) = 0
Next j
cmdTest.Caption = "试验老链"
凳铅 Else
For j = 0 To 359
c(j) = j * a / 60
record(0, j) = Sin(c(j)) * -450
record(1, j) = Sin(c(j)) * -300
record(2, j) = Sin(c(j) + a / 3) * -450
record(3, j) = Sin(c(j) + 2 * a / 3) * -450
record(4, j) = Sin(c(j) + 2 * a / 3) * -300
record(5, j) = Sin(c(j) + 2 * a / 3) * -150
Next j
cmdTest.Caption = "记录"
End If
cmdTestFlag = Not cmdTestFlag
End Sub
Private Sub Timer1_Timer()
If 枣含好lblTime.Caption <> CStr(Time$) Then
lblTime.Caption = Time$
Frmjly.Caption = "记录仪" & Space(90) & Date$ & Space(6) & Time$
miao1 = Mid(lblTime, 7, 2)
fen1 = Mid(Time$, 4, 2)
If fen1 = 0 And miao1 = 0 Then
shijian(0) = lblTime
End If
Label1 = lblTime
If miao1 = 0 Then
For k = 0 To 358
record_zh(0, k + 1) = record(0, k)
record_zh(1, k + 1) = record(1, k)
record_zh(2, k + 1) = record(2, k)
record_zh(3, k + 1) = record(3, k)
record_zh(4, k + 1) = record(4, k)
record_zh(5, k + 1) = record(5, k)
Next k
For j = 1 To 359 '9
record(0, j) = record_zh(0, j)
record(1, j) = record_zh(1, j)
record(2, j) = record_zh(2, j)
record(3, j) = record_zh(3, j)
record(4, j) = record_zh(4, j)
record(5, j) = record_zh(5, j)
Next j
End If
If fen1 = 0 And miao1 = 1 Then
For ii = 0 To 5
shijian_zh(ii + 1) = shijian(ii)
Next ii
For h = 1 To 6
shijian(h) = shijian_zh(h)
Next h
Label1.Visible = False
Label2.Visible = True
End If
End If
End Sub
Private Sub Timer2_Timer()
BitBlt Me.Picture1.hDC, 0, 0, Me.Picture1.ScaleWidth, Me.Picture1.ScaleHeight, 0, 0, 0, vbBlack 'ness
Text1 = Time$
miao = Right$(Time$, 2)
Text2 = fen1
record(0, 0) = record_jm(3) * -30
record(1, 0) = record_jm(4) * -30
record(2, 0) = record_jm(5) * -30
record(3, 0) = record_jm(0) * -30
record(4, 0) = record_jm(1) * -30
record(5, 0) = record_jm(10) * -30 '干箱真空
mmm = Val(fen1 * 60) + Val(miao)
j = mmm
p = (j / 360) - Int(j / 360)
j = p * 360
Text2 = Date$
Label8 = Date$
Label2 = shijian(1)
Label2.Left = fen1 * 30 + 140
Label3 = shijian(2)
Label3.Left = fen1 * 30 + 1800 * 1 + 140
Label4 = shijian(3)
Label4.Left = fen1 * 30 + 1800 * 2 + 140
Label5 = shijian(4)
Label5.Left = fen1 * 30 + 1800 * 3 + 140
Label6 = shijian(5)
Label6.Left = fen1 * 30 + 1800 * 4 + 140
Label7 = shijian(6)
Label7.Left = fen1 * 30 + 1800 * 5 + 140
'温度坐标
colvb = vbWhite
xx = 100
yy = 150
txt = "℃"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 200
yy = 1850
txt = "50"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 300
txt = "0"
wp = xp(colvb, xx, yy, txt)
xx = 100
yy = 4850
txt = "-50"
wp = xp(colvb, xx, yy, txt)
xx = 0
yy = 6350
txt = "-100"
wp = xp(colvb, xx, yy, txt)
'真空坐标
colvb = vbRed
xx = 11500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "10000"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 1850
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 11500
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 4850
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 11500
yy = 6350
txt = "1"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 150
txt = "Pa"
wp = xp(colvb, xx, yy, txt)
yy = 350
txt = "10000"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 1850
txt = "1000"
wp = xp(colvb, xx, yy, txt)
yy = 3350
xx = 500
txt = "100"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 4850
txt = "10"
wp = xp(colvb, xx, yy, txt)
xx = 500
yy = 6350
txt = "1"
wp = xp(colvb, xx, yy, txt)
'画格
Picture1.ForeColor = vbWhite
Picture1.Line (450, 400)-(11300, 400)
Picture1.Line (450, 700)-(500, 700)
Picture1.Line (450, 1000)-(500, 1000)
Picture1.Line (450, 1300)-(500, 1300)
Picture1.Line (450, 1600)-(500, 1600)
Picture1.ForeColor = vbRed
Picture1.Line (500, 566.7)-(550, 566.7)
Picture1.Line (500, 733.3)-(550, 733.3)
Picture1.Line (500, 900)-(550, 900)
Picture1.Line (500, 1066.7)-(550, 1066.7)
Picture1.Line (500, 1233.3)-(550, 1233.3)
Picture1.Line (500, 1400)-(550, 1400)
Picture1.Line (500, 1566.7)-(550, 1566.7)
Picture1.Line (500, 1733.3)-(550, 1733.3)
Picture1.Line (500, 2066.7)-(550, 2066.7)
Picture1.Line (500, 2233.3)-(550, 2233.3)
Picture1.Line (500, 2400)-(550, 2400)
Picture1.Line (500, 2566.7)-(550, 2566.7)
Picture1.Line (500, 2733.3)-(550, 2733.3)
Picture1.Line (500, 2900)-(550, 2900)
Picture1.Line (500, 3066.7)-(550, 3066.7)
Picture1.Line (500, 3233.3)-(550, 3233.3)
Picture1.Line (500, 3566.7)-(550, 3566.7)
Picture1.Line (500, 3733.3)-(550, 3733.3)
Picture1.Line (500, 3900)-(550, 3900)
Picture1.Line (500, 4066.7)-(550, 4066.7)
Picture1.Line (500, 4233.3)-(550, 4233.3)
Picture1.Line (500, 4400)-(550, 4400)
Picture1.Line (500, 4566.7)-(550, 4566.7)
Picture1.Line (500, 4733.3)-(550, 4733.3)
Picture1.Line (500, 5066.7)-(550, 5066.7)
Picture1.Line (500, 5233.3)-(550, 5233.3)
Picture1.Line (500, 5400)-(550, 5400)
Picture1.Line (500, 5566.7)-(550, 5566.7)
Picture1.Line (500, 5733.3)-(550, 5733.3)
Picture1.Line (500, 5900)-(550, 5900)
Picture1.Line (500, 6066.7)-(550, 6066.7)
Picture1.Line (500, 6233.3)-(550, 6233.3)
Picture1.ForeColor = vbWhite
Picture1.Line (450, 1900)-(11300, 1900)
Picture1.Line (450, 2200)-(500, 2200)
Picture1.Line (450, 2500)-(500, 2500)
Picture1.Line (450, 2800)-(500, 2800)
Picture1.Line (450, 3100)-(500, 3100)
Picture1.Line (450, 3400)-(11300, 3400)
Picture1.Line (450, 3700)-(500, 3700)
Picture1.Line (450, 4000)-(500, 4000)
Picture1.Line (450, 4300)-(500, 4300)
Picture1.Line (450, 4600)-(500, 4600)
Picture1.Line (450, 4900)-(11300, 4900)
Picture1.Line (450, 5200)-(500, 5200)
Picture1.Line (450, 5500)-(500, 5500)
Picture1.Line (450, 5800)-(500, 5800)
Picture1.Line (450, 6100)-(500, 6100)
Picture1.Line (450, 6400)-(11300, 6400)
Picture1.Line (500, 400)-(500, 6400)
Picture1.Line (11300, 400)-(11300, 6400)
'画时间坐标
'Picture1.ForeColor = vbYellow
If -700 + fen1 * 30 > 200 Then
Picture1.Line (-400 + fen1 * 30, 400)-(-400 + fen1 * 30, 6400)
End If
Picture1.Line (500 + fen1 * 30, 400)-(500 + fen1 * 30, 6400)
Picture1.Line (1400 + fen1 * 30, 400)-(1400 + fen1 * 30, 6400)
Picture1.Line (2300 + fen1 * 30, 400)-(2300 + fen1 * 30, 6400)
Picture1.Line (3200 + fen1 * 30, 400)-(3200 + fen1 * 30, 6400)
Picture1.Line (4100 + fen1 * 30, 400)-(4100 + fen1 * 30, 6400)
Picture1.Line (5000 + fen1 * 30, 400)-(5000 + fen1 * 30, 6400)
Picture1.Line (5900 + fen1 * 30, 400)-(5900 + fen1 * 30, 6400)
Picture1.Line (6800 + fen1 * 30, 400)-(6800 + fen1 * 30, 6400)
Picture1.Line (7700 + fen1 * 30, 400)-(7700 + fen1 * 30, 6400)
Picture1.Line (8600 + fen1 * 30, 400)-(8600 + fen1 * 30, 6400)
Picture1.Line (9500 + fen1 * 30, 400)-(9500 + fen1 * 30, 6400)
If 10400 + fen1 * 30 < 11300 Then
Picture1.Line (10400 + fen1 * 30, 400)-(10400 + fen1 * 30, 6400)
End If
If 11300 + fen1 * 30 < 11300 Then
Picture1.Line (11300 + fen1 * 30, 400)-(11300 + fen1 * 30, 6400)
End If
'显示记录
Picture1.ForeColor = vbYellow
For j = 0 To 359
Picture1.Line (j * 30 + 500, record(0, j) + 3395)-(j * 30 + 502, record(0, j) + 3405), vbRed, BF
Picture1.Line (j * 30 + 500, record(1, j) + 3395)-(j * 30 + 502, record(1, j) + 3405), QBColor(7), BF
Picture1.Line (j * 30 + 500, record(2, j) + 3395)-(j * 30 + 502, record(2, j) + 3405), vbWhite, BF
Picture1.Line (j * 30 + 500, record(3, j) + 3395)-(j * 30 + 502, record(3, j) + 3405), vbYellow, BF
Picture1.Line (j * 30 + 500, record(4, j) + 3395)-(j * 30 + 502, record(4, j) + 3405), vbGreen, BF
If record(5, j) / -30 < 10 Then
wy_wy = -0 + 166.7
br_br = 5.5556
ElseIf record(5, j) / -30 >= 10 And record(5, j) / -30 < 100 Then
wy_wy = -1500 + 166.7
br_br = 0.5555
ElseIf record(5, j) / -30 >= 100 And record(5, j) / -30 < 1000 Then
wy_wy = -3000 + 166.7
br_br = 0.055555
ElseIf record(5, j) / -30 >= 1000 And record(5, j) / -30 < 10000 Then
wy_wy = -4500 + 166.7
br_br = 0.0055555
End If
Picture1.Line (j * 30 + 500, record(5, j) * br_br + wy_wy + 3395 + 3000)-(j * 30 + 502, record(5, j) * br_br + wy_wy + 3405 + 3000), QBColor(11), BF
Next j
Picture1.Refresh
End Sub
上述Line曲线方法代码可很方便移植为Pset方法绘制曲线。
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
2014-03-25
展开全部
使模乱用PictureBox的腔悔Line方法 以Scale区间定位 实时数据连续滚动曲线可以伍码正使用两个PictureBox轮番交替
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在VB6里可以在两种对象上绘敬前制图形,一个是窗体,另一个是PicTureBox ,它们都有Pset 等方法
Pset方法是绘制点,
格式:
对象.Pset (x,y)
其中:x,y 点的坐标,
理论上,点的铅稿嫌集合构成线。
把一个一个实数对,绘制出来,就构槐手成了曲线。
Pset方法是绘制点,
格式:
对象.Pset (x,y)
其中:x,y 点的坐标,
理论上,点的铅稿嫌集合构成线。
把一个一个实数对,绘制出来,就构槐手成了曲线。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-03-26
展开全部
用timer 和line 就行了,每采集一个数据就画一张picture
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-03-26
展开全部
picture控件画图啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询