【问题标题】:.net how to remove the oldest data XY point and then add a new XY data point to chart.net 如何删除最旧的数据 XY 点,然后将新的 XY 数据点添加到图表
【发布时间】:2018-12-11 01:41:39
【问题描述】:

我正在使用 .Points.RemoveAt(0) 删除最旧的和 .AddXY 添加最新的。

但图表无法正常工作。当我删除每个最旧的并添加每个最新的(x 轴是时间)时,我没有看到图表向左滚动,正如我所料。

【问题讨论】:

  • 不用这样,你可以在序列.Points()数组中移动点。
  • 看看this post如何做到这一点。

标签: c# .net charts series


【解决方案1】:

糟糕,我用 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

【讨论】:

  • 糟糕,我用 VBA 代替了C#
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
相关资源
最近更新 更多