Drop data from HighLowSeries

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Arction_LasseP

Posts: 10
Joined: Wed Jun 29, 2016 3:34 pm

Drop data from HighLowSeries

Post by michel » Wed Mar 30, 2022 6:26 am

I have a requirement to drop old data from a HighLowSeries manually every 30 minutes or so. Currently i've implemented this as follows:

- copy the highlowseriespoints to a temporary list. (highlow.Points.ToList().GetRange(0, highlow.PointCount))
- remove old highlowseriespoints from temporary list.
- clear highlowseries (highlow.Clear())
- add temporary list to highlowseries (highlow.AddValues(templist.ToArray())

It seems this results in a memory leak somehow. What is the correct way to do this?

Posts: 439
Joined: Mon Mar 14, 2016 9:22 am

Re: Drop data from HighLowSeries

Post by ArctionKestutis » Thu Mar 31, 2022 8:48 am

For progressive line series (like HighLowSeries) LightningChart has automatic point dropping functionality. That is, Series' Point/Samples array is made shorter periodically. Whatever LightningChart ViewXY keeps out-scrolled data is controlled by _chart.ViewXY.DropOldSeriesData property. A fine-tuning of how many points is kept done with Series.ScrollModePointsKeepLevel property. It controls how many pages of old data is kept before deleting the old points. One page means range from minimum X-value to maximum X-value. ScrollModePointsKeepLevel = 10 means one page; 20 - two pages; 100 - 10 pages etc.
Note, that above automated point dropping depends on XAxis visible range. Therefore, zooming would change the amount of points to be dropped.

If auto point dropping does not satisfy your needs, or you want more control over this process, then use following method

Code: Select all

void DeletePointsBeforeX(HighLowSeries series, double xValue)
	int iPointsToDelete = 0;
	HighLowSeriesPoint[] m_points = series.Points;
	int m_iActualPointCount = series.PointCount;

	for (int i = 0; i < m_points.Length; i++)
		if (m_points[i].X < xValue)

	int iNewArraySize = (m_iActualPointCount - iPointsToDelete); 

	HighLowSeriesPoint[] aNewPointArray = new HighLowSeriesPoint[iNewArraySize];

	//Copy the data to be kept
	Array.Copy(m_points, iPointsToDelete, aNewPointArray, 0, m_iActualPointCount - iPointsToDelete);
	series.Points = aNewPointArray;
Note, that other progressive line series already have public method to do just that (i.e. DeleteSamplesBeforeX() or DeletePointsBeforeX()). In next release we will make public method for HighLowSeries as well.

Hope this helps.

Posts: 439
Joined: Mon Mar 14, 2016 9:22 am

Re: Drop data from HighLowSeries

Post by ArctionKestutis » Fri May 27, 2022 12:09 pm

LightningChart .NET version 10.3 was released few days ago and HighLowSeries now has public method DeletePointsBeforeX().