RealtimeChart特点是随着时间的推移,会在左侧移除掉多余的散点。
如果用户要回放之前的散点,会带来两个问题:
1.移除的散点需要保存到一个集合或者数据库中,才能再次看到,是这种搞法吧?
2.加载移除的散点时,实时采集仍要进行。此时,应该怎样将移除的散点与实时采集的散点整合在一个曲线图里?
DateTime argument = DateTime.Now;
SeriesPoint[] pointsToUpdate1 = new SeriesPoint[Interval];
SeriesPoint[] pointsToUpdate2 = new SeriesPoint[Interval];
for (int i = 0; i < Interval; i++) {
pointsToUpdate1[i] = new SeriesPoint(argument, value1);
pointsToUpdate2[i] = new SeriesPoint(argument, value2);
argument = argument.AddMilliseconds(1);
UpdateValues();
}
DateTime minDate = argument.AddSeconds(-TimeInterval);
int pointsToRemoveCount = 0;
foreach (SeriesPoint point in Series1.Points)
if (point.DateTimeArgument < minDate)
pointsToRemoveCount++;
if (pointsToRemoveCount < Series1.Points.Count)
pointsToRemoveCount--;
AddPoints(Series1, pointsToUpdate1);
AddPoints(Series2, pointsToUpdate2);
if (pointsToRemoveCount > 0) {
Series1.Points.RemoveRange(0, pointsToRemoveCount);
Series2.Points.RemoveRange(0, pointsToRemoveCount);
}
SwiftPlotDiagram diagram = chart.Diagram as SwiftPlotDiagram;
if (diagram != null && (diagram.AxisX.DateTimeScaleOptions.MeasureUnit == DateTimeMeasureUnit.Millisecond || diagram.AxisX.DateTimeScaleOptions.ScaleMode == ScaleMode.Continuous))
diagram.AxisX.WholeRange.SetMinMaxValues(minDate, argument);