Page 1 of 1

Drop data from HighLowSeries

Posted: Wed Mar 30, 2022 6:26 am
by michel
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?

Re: Drop data from HighLowSeries

Posted: Thu Mar 31, 2022 8:48 am
by ArctionKestutis
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)
			iPointsToDelete++;
		else
			break;
	}

	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.

Re: Drop data from HighLowSeries

Posted: Fri May 27, 2022 12:09 pm
by ArctionKestutis
LightningChart .NET version 10.3 was released few days ago and HighLowSeries now has public method DeletePointsBeforeX().