Possible to check if a data point (X,Y) has already been added to a series?

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

dgermana wrote at 2013-12-11 19:57:

Hello,
I'm using OxyPlot in an application to display a series of data that repeats, but with some noise in the data. The resulting chart looks similar to how an oscilloscope would look if you were triggering on a sine wave. When I plot just one cycle of data, and clear the points between each cycle, everything works great.

However, when I enable a "persistence" mode, where all old points remain in the series so that all past data is displayed in the chart, the updates get really slow after awhile. I assume this is because the number of points in the series becomes very large. Since the data is very nearly repeated for each cycle, but with some noise, the vast majority of "new" data points are identical to old data points that have already been added to the series. I'm thinking that if I could somehow check whether a particular X,Y data point already exists in the series, I could avoid adding a bunch of redundant data to the series, therefore keeping the number of points much smaller with the goal of avoiding the extremely slow updates.

So, with that background, my questions are:
  • Is it possible to check whether a point exists in the series?
  • How? Maybe something like:
    if (series.Points.contains(X,Y))
        // Discard the new X,Y point
    else
        series.Points.Add(new DataPoint(X, Y));
Thank you so much for any help or suggestions!

Dominic

objo wrote at 2013-12-11 20:14:

You can use Enumerable.Any
In your code: series.Points.Any(p => p.X.Equals(X) && p.Y.Equals(Y))
See also 'Testing for equality' on http://msdn.microsoft.com/en-us/library/system.double.aspx

dgermana wrote at 2013-12-11 20:49:

Thank you so much for the very fast response! That looks like it will do what I need. Now I will test to see if this strategy keeps my plot updates from bogging down...

Thank you again so much! I will report back with the results of my test.

Dominic

dgermana wrote at 2013-12-12 16:00:

Thank you again for your help objo.

I would like to be able to get the list index for the point that matches. I found some references to a FindIndex() method of lists, but when I try to to do:
series.Points.FindIndex(p => p.X.Equals(X) && p.Y.Equals(Y))
I get an error saying that OxyPlot.IDataPoint does not contain a definition for FindIndex. I thought that since Any was supported, FindIndex would be supported also.

At this point I really just need to get the index for the first Points entry that matches the X value.

Do you have any suggestions? Thank you again so much for your help..

Dominic