How to limit point count (ViewXY)?
While it is possible to add more and more points to chart or line-series almost indefinitely, at some stage it will become impractical and starts to consume too much memory. Especially true for long running real-time/streaming application, where the main interest is to observe/visualize the latest points. Therefore, it is a good idea to have point limiting strategy implemented in the streaming application.
DropOldSeriesData
ViewXY has property DropOldSeriesData (and DropOldEventMarkers), which automatically deletes series data (or event markers), whose x value is less than X-axis minimum. By setting this true, user will be able to maintain stable points count (points outside visible axis range will be deleted, when new points are added with AddPoints() or AddSamples() methods).
The amount of dropped points can be adjusted with Series. ScrollModePointsKeepLevel property. It controls how often the draw data is cleared when using X axis scroll mode. Valid range is 1...100. Where 1 frees the draw data and the reconstructs the draw data after every 1/10 scroll page (Page = Axis range Maximum-Minimum). 100 frees the draw data and the reconstructs the draw data after every 100/10 = 10 pages.
If user will zoom-in XAxis during (and DropOldSeriesData is enabled) and zoom-out, the line drawn on the chart may be shorted from the left side. This happens due to Axis.Minimum temporary being large value, and therefore, more points will be dropped.
DeleteSamplesBeforeX / DeletePointsBeforeX
If user needs more flexibility (when and how many points are deleted), and negate zooming issues described in the note above, then Series. DeleteSamplesBeforeX() method (for SampleDataBlockSeries / SampleDataSeries) or DeletePointsBeforeX() method (for other progressive x-value line-series) can be used. When those methods are used, property ViewXY. DropOldSeriesData should be disabled.
PointCountLimit
Freeform point line-series (LiteFreeformLineSeries or FreeformPointLineSeries) points are not automatically destroyed even if DropOldSeriesData is enabled, and the points are scrolled out of current view. To automatically destroy old series points in real-time monitoring solution, use point count limiter. Set Series. PointCountLimitEnabled = true and set the limit to PointCountLimit property. If limiter is enabled, the Points array behaves as a ring buffer after the point count limit has been reached. The oldest point from Points array can always be found by retrieving value from OldestPointIndex (for FreeformPointLineSeries). If needing to read the existing data out of point count limited buffer, use the following method:
- If OldestPointIndex is 0, read from Points[0] till Points[PointCount-1].
- If OldestPointIndex > 0, first read from Points[OldestPointIndex] till Points[PointCountLimit-1]. Then, read from Points[0] till Points[OldestPointIndex-1].
- To directly retrieve the last series point, call GetLastPoint() method (for FreeformPointLineSeries).
"Brutal force" approach
Some line-series XY has Points property/array (or in case of SampleDataSeries properties SamplesDouble / SamplesSingle), which gets or sets series points. (But not BlockSeriesBase type or LineCollection).
Therefore, it is possible at any phase of app running to create new array of points and assign to corresponding property. E.g.
SeriesPoint[] newPoints = new SeriesPoint[n];
//...create new array
series.Points = newPoints;
However, this approach is not very efficient or fast for scrolling/sweeping XAxis, especially when array size increase and a lot of copying is required.
When series methods like AddPoints(), AddValues() or AddSamples() are used new points are added at the end of array/series. However, to facilitate Real-time monitoring scrolling, those methods actually increase points-array size more than actual points added. This is to reduce the need to resize array next time points are added. Therefore, user shouldn't blindly copy all old Points to newPoints. Instead, Series. PointCount should always be used, as it tells which points are 'real' from the start of array.