有点不适合套用我的函数画图。我的图是不支持滚动条。也就是说压了多少数据进去 ,就画多少点。
而你的要求是 120个点,界面上只显示 30个点,其它点可以通过滚动条来查看。

授人于鱼,不如授人于渔
早已停用QQ了
程序代码:Dim px(121) As Single, py(121) As Single '用来保存曲线数据的坐标值,程序中实时曲线通道为30. '仅使用前30个元素
Dim col As Integer '当前需绘制的点数 '未使用
Dim pl As Integer '判断是否画动态曲线 '未使用
Private Sub Command1_Click()
Timer2.Enabled = True
If Timer1.Enabled = True Then
Command1.Caption = "开始"
Timer1.Enabled = False
Else
Command1.Caption = "暂停"
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
HScroll1.value = 1
Picture1.Scale (900, 0)-(1200, 300) '设置绘图区域坐标
'移到这里
Randomize
End Sub
Private Sub HScroll1_Change()
Call Timer1_Timer
'此段函数清空
'Picture1.Cls '清空绘图区域
'num = HScroll1.value '使绘图区域坐标和滚动条对应
'Picture1.Scale (900 - (900 - num), 0)-(1200 - (900 - num), 300)
'If pl >= 2 Then
'Picture1.PSet (px(0), py(0))
'For i = 1 To col
'Picture1.Line -(px(i - 1), py(i - 1)), QBColor(2) ' 重绘曲线
'Next i
'End If
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
Dim i As Long
Dim j As Long
Dim k As Long
'把 list1 当作数据缓冲,直接到里面读数据
i = List1.ListCount - 1 '总数据量
j = HScroll1.value '滚动条位置,决定起始位置
If j > i Then Exit Sub '如果没读到数据,不执行读数据和绘图功能,直接退出处理
If i - j > 31 Then i = j + 31 '确保只取 31 个值
'j 是滚动条的值,也就是开始位置
'i 是终止值,list1 中的总记录数 或 比 J 大 30
For k = 0 To i - j
px(k) = 900 + (k) * 10
py(k) = Val(List1.List(k + j))
Next k
For i = 1 To i - j
Picture1.Line (px(i - 1), py(i - 1))-(px(i), py(i)), QBColor(2) '使用省略参数进行绘图,老出错,只好用标准命令
Next i
'If col < 31 Then
' For i = 0 To col
' px(i) = 900 + i * 10
' py(i) = Val(List1.List(i)) '利用随机数模拟实际数据
' Next i
' col = col + 1
' pl = pl + 1
'ElseIf col < 121 Then
' For j = 0 To col
' py(j) = Val(List1.List(j))'Picture1.Cls
'
'If List1.ListCount > 1 Then
'Call ADDDATA(List1.List(List1.ListCount - 1)) '把最后一个数据加进去。
'End If
' px(j) = 1200 - 10 * (col - j) '如果数据点数》30 《121,数据的横坐标则用这个式子赋值
' Next j
' col = col + 1 '当数组装满时顺次前移,将数组第一个去掉
'Else
' For t = 0 To 119
' py(t) = py(t + 1)
' px(t) = 1200 - 10 * (col - t)
' Next t
' py(120) = Val(List1.List(i))
' '数组的最后一个元素始终存放当前最新实时数据
'End If
'If pl >= 2 Then '在两个或两个以上的数据点时,开始画动态曲线
' Picture1.PSet (px(0), py(0))
' For i = 1 To col
' Picture1.Line -(px(i - 1), py(i - 1)), QBColor(2)
' Next i
'End If
End Sub
Private Sub Timer2_Timer()
Dim value As Integer
value = Int(200 * Rnd + 100)
List1.AddItem value
'list1中最多保存930条记录,HScroll1.max + 30
If List1.ListCount > 930 Then
List1.RemoveItem 0
End If
End Sub
