Page 1 of 1

Remove old data points

Posted: Mon Dec 21, 2015 9:47 am
by Igor
Hi,

my chart control should remove automatically old data points.
The buffer size should be configurable by the user, for example the last 10 seconds.

I see currently 2 ways how I can dispose old data points.

1. chart.ViewXY.DropOldSeriesData = true;
But I can't adjust the period of time. Is that correct?

2. In the PointLineSeries I could call "series.DeletePointsBeforeX (_latestX - 10)" manually.
But in the chart that has only an effect when the user interacting with the chart control, for example MouseMove on the PointLineSeries or
when scrolling.

What is the best way to do this?

Re: Remove old data points

Posted: Tue Dec 22, 2015 11:55 am
by ArctionPasi
Hi Igor,

There's no property to control it directly like that. Deleting extra points every time a new data point is added is very resource consuming and for performance reasons we don't do that. It's eventually a large points array we are dealing with, not a list.

PointLineSeries, SampleDataSeries, HighLowSeries and AreaSeries have ScrollModePointsKeepLevel to control how many pages of data is to be kept before cutting it from X axis minimum. One page = X min ... X Max. The ScrollModePointsKeepLevel 10 = means one page. 20 = two pages. 1 = 0.1 pages. etc.

To manually delete points now then at specific intervals, you can write an event handler for X axis RangeChanged.

Code: Select all

private const double IntervalForDrop = 5; //seconds
private const double DataKeepLen = 2; //seconds

void ExampleTemperatureGraph_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            AxisX xAxis = m_chart.ViewXY.XAxes[0]; 
            
            PointLineSeries pls = m_chart.ViewXY.PointLineSeries[0];
            if(pls.PointCount > 0 && pls.Points[0].X < xAxis.Minimum - IntervalForDrop)
            {
                cancelRendering = true;
            
                m_chart.BeginUpdate();
                pls.DeletePointsBeforeX(m_chart.ViewXY.XAxes[0].Minimum - DataKeepLen); 

                m_chart.EndUpdate();
            } 
        }

Re: Remove old data points

Posted: Tue Dec 22, 2015 12:00 pm
by ArctionPasi
Hi Igor,

There's no property to control it directly like that. Deleting extra points every time a new data point is added is very resource consuming and for performance reasons we don't do that. It's eventually a large points array we are dealing with, not a list.

PointLineSeries, SampleDataSeries, HighLowSeries and AreaSeries have ScrollModePointsKeepLevel to control how many pages of data is to be kept before cutting it from X axis minimum. One page = X min ... X Max. The ScrollModePointsKeepLevel 10 = means one page. 20 = two pages. 1 = 0.1 pages. etc.

To manually delete points now then at specific intervals, you can write an event handler for X axis RangeChanged.

Code: Select all

private const double IntervalForDrop = 5; //seconds
private const double DataKeepLen = 2; //seconds

void ExampleTemperatureGraph_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            AxisX xAxis = m_chart.ViewXY.XAxes[0]; 
            
            PointLineSeries pls = m_chart.ViewXY.PointLineSeries[0];
            if(pls.PointCount > 0 && pls.Points[0].X < xAxis.Minimum - IntervalForDrop)
            {
                cancelRendering = true;
            
                m_chart.BeginUpdate();
                pls.DeletePointsBeforeX(m_chart.ViewXY.XAxes[0].Minimum - DataKeepLen); 

                m_chart.EndUpdate();
            } 
        }

Re: Remove old data points

Posted: Wed Dec 23, 2015 8:27 am
by Igor
1. Variant: with "Pages" and "ScrollModePointsKeepLevel"
That's unfortunately not works for me, because if the user zooms in it will already delete datapoints.
Hint: To make this work you have to set the Property "Chart.ViewXY.DropOldSeriesData" to true.

2. Variant: Delete manually like in your example:
The performance breaks extremely if you set "DataKeepLen" to a higher value then "IntervalForDrop",
if your chart has more than one PointLineSeries.


My solution:
I call the method "pls.DeletePointsBeforeX (..)" directly after filling the data series.
This runs most fluid and does what I like.

Thank you