我正在使用.Points.RemoveAt(0)删除最早的 .AddXY添加最新的内容。
但是图表运行不正确。删除每个最旧的数据并添加每个最新的数据(x轴是时间)时,我没有看到图表向左滚动,就像我期望的那样。
答案 0 :(得分:0)
糟糕,我是用VBA(而不是
C#
)回答的。好吧,也许您可以通过读取值数组,对其进行修改并将其写回到图表中来在C#
中做同样的事情。
我认为您正在尝试做这样的事情:
这是我用来执行此操作的代码:
Private Const MaxPoints As Long = 100
Private Sub CommandButton1_Click()
Dim i As Long, PI As Double
PI = 4 * Atn(1)
For i = 1 To 720 / 5
AddValueToChart 50# + 35# * Sin(5 * i * PI / 180)
DoEvents
Next i
End Sub
Public Sub AddValueToChart(ByVal x As Double)
Dim ch As Chart, list() As Variant
Set ch = Me.ChartObjects("Chart 1").Chart
Dim serlist As SeriesCollection
Set serlist = ch.SeriesCollection()
' If chart is empty then add a line with 100 points
If serlist.Count = 0 Then
serlist.NewSeries
ReDim list(1 To MaxPoints)
ch.SeriesCollection(1).Values = list
End If
Dim ser As Series
Set ser = ch.SeriesCollection(1)
' Get an array of values
list = ser.Values
Dim i As Long
For i = MaxPoints To 2 Step -1
' Shift points
list(i) = list(i - 1)
Next i
' Add a new point to the begining of the chart.
list(1) = x
' Assign the modified list as values of the series.
ser.Values = list
End Sub