Search code examples
wpfoxyplotlineseries

Oxyplot with WPF


I am working with and I oxyplot download an example the following link: http://blog.bartdemeyer.be/2013/03/creating-graphs-in-wpf-using-oxyplot/

I added my own data plotting to go, but the incoming points are accumulated and that makes the graph becomes unreadable.

how I do like to go update the chart so that the old points are eliminated and new points are displayed normally and not stacked.

http://blog.bartdemeyer.be/wp-content/uploads/image_thumb19.png


Solution

  • Use LineSeries.Points.RemoveAt(index)

    Example:

    (DataPlot.Series[0] as LineSeries).Points.Add(new DataPoint(xValue, yValue0));
    (DataPlot.Series[1] as LineSeries).Points.Add(new DataPoint(xValue, yValue1));   
    if (valueRange > 10000) //points will accumulate until the x-axis reaches 10000
        { //after 10000
         (DataPlot.Series[0] as LineSeries).Points.RemoveAt(0); //removes first point of first series
         (DataPlot.Series[1] as LineSeries).Points.RemoveAt(0); //removes first point of second series
        }
    

    But you must use it together - adding one new point and removing one. Then the points will not accumulate and you will have x-axis of range you wish.