10

VB 绘制曲线图 一段时间后 数据走势总会归 X轴一次

先上代码:

Option Explicit
Const max_x As Long = 16
Const max_y As Long = 30

Private arr(max_x) As Single
Private arrIndex As Long ' 最后采样的点
Dim dtTime As Date
Dim numberss As Integer

Private Sub SubShow()
Dim j As Long, x As Long
Dim q(max_x) As Single
Dim dtTime As Date
Timer1.Interval = 1000
Timer1.Enabled = True
Picture1.Cls
Picture1.ScaleMode = vbPixels '<-不应该是 Form1 吧,还有要用常量'
Picture1.DrawWidth = 1
Picture1.Scale (-0.5, max_y)-(max_x, -3)
Picture1.Line (0, 0)-(max_x, 0)
Picture1.Line (0, 0)-(0, max_y)
Picture1.CurrentX = 14.5: Picture1.CurrentY = 0.3: Picture1.Print "X/秒"
Picture1.CurrentX = 0.2: Picture1.CurrentY = 5.9: Picture1.Print "Y/m^3/s"
For j = 0 To 15
Picture1.DrawStyle = 2
Picture1.Line (j, 0)-(j, 6)
Next j
For j = 1 To 30
Picture1.DrawStyle = 2
Picture1.Line (0, j)-(31, j)
Picture1.CurrentX = -0.4: Picture1.CurrentY = j
Picture1.Print j
Next j

dtTime = DateAdd("s", -max_x, time)
For x = 0 To max_x
    Picture1.DrawStyle = 0
    Picture1.DrawWidth = 3

    '绘图时将环按采样的时间次序重排'
    q(x) = arr((x + arrIndex + 1) Mod (max_x + 1))

    If x > 0 Then
        Picture1.Line ((x - 1), q(x - 1))-(x, q(x))
    End If
    Picture1.CurrentX = x - 0.5: Picture1.CurrentY = 0
    Picture1.Print Format(dtTime, "HH:mm:ss")
    dtTime = DateAdd("s", 1, dtTime)
    Picture1.CurrentX = x - 0.5: Picture1.CurrentY = q(x) + 0.5
    Picture1.Print q(x)
Next
Picture1.CurrentX = 7: Picture1.CurrentY = 6
Picture1.Print arrIndex

End Sub

Public Sub Timer1_Timer()

numberss = numberss + 1
arrIndex = (arrIndex + 1) Mod max_x
arr(arrIndex) = TempArr(numberss)
SubShow
End Sub
效果如图:
图片说明

问题就是 为何经过一定周期,数据总会归0于x轴。TempArr中一直都是有数据的 这是怎么回事?

查看全部
qq_33673312
qq_33673312
2017/03/09 09:27
  • vb
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复