0

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;
Lukeyb
  • 807
  • 6
  • 24
  • Maybe the problem is on the binding, so the changes are made but not reflected on the view. Could you show the binding part? – Jose Dec 13 '16 at 07:50
  • In your code, I don't see a delay between adding and removing points. Maybe it is happening so fast that you don't see the animation??? Also try using _plotModel.InvalidatePlot(true) instead of _plotView.InvalidatePlot(true) – Drunken Daddy Dec 13 '16 at 09:47
  • Try using MVVM aproach, bind the model on the view(xaml), instead of access plotview properties from code behind. – Jose Dec 13 '16 at 11:01

0 Answers0