I'm trying to make a line series graph in Oxyplot that wraps around back to the beginning, but I'm having a difficult time removing old points from the graph. I've tried both the Series.Remove and Series.RemoveAt methods, but neither have worked. My plot ends up tracing over itself, even when the remove method is returning true (indicating it thinks it successfully removed the data point).
I have my animate method hooked up to an event which passes in the new data to add to the plot. I'm trying to clear (clearGap) number of points ahead of the new data so the new data can be distinguished from the old data. The try/catch is there to handle the first run through when there are no data points to remove yet.
void AnimatePlot(double[] data)
{
clearIndex = plotIndex + clearGap;
List<double> plotData = data.ToList();
RunOnUiThread(() =>
{
for (int i = 0; i < plotData.Count; i++)
{
if (clearIndex < _plotBottomMax)
{
try
{
var res = lsPlot1.Points.Remove(lsPlot1.Points[clearIndex].);
}
catch (Exception e)
{
;
}
clearIndex++;
}
else
{
clearIndex = 0;
try
{
var res = lsPlot1.Points.Remove(lsPlot1.Points[clearIndex]);
}
catch (Exception e)
{
;
}
clearIndex++;
}
if (plotIndex < _plotBottomMax)
{
lsPlot1.Points.Add(new DataPoint(plotIndex, plotData[i]));
plotIndex++;
}
else
{
plotIndex = 0;
lsPlot1.Points.Add(new DataPoint(plotIndex, plotData[i]));
plotIndex++;
}
}
//Unlock the plot so we can animate it
_plotView.InvalidatePlot(true);
});
}
In case it isn't clear, points will be plotted until they reach the edge of the graph (_plotBottomMax), then the plot index will be reset to 0 and it will start again.
How do you correctly delete points from a location within the series?
EDIT: Binding the series to the plot:
_lsPlot1 = new LineSeries
{
LineStyle = LineStyle.Solid,
StrokeThickness = 1,
Title = "Signal",
YAxisKey = "yAxis",
Color = OxyColor.FromRgb(255, 0, 0)
};
//Add plot's LineSeries into the model
_plotModel.Series.Add(_lsPlot1);
//Set Plot View's Model
plotView.Model = _ecgPlotModel;