how to get the max point coordinate on the showing screen?

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

aoi wrote at 2014-05-21 05:22:

I use oxyplot to show 2048 points, when I zoom specific area, how to get the max point coordinate on the showing screen, not the max point of the whole data?
Any ideas how I can do that?

everytimer wrote at 2014-05-21 07:32:

What do you need for getting the maximum of the whole data is:
MyData.Select( p => p.Y).Max();
For the data shown in the ViewPort: Get the ActualMinimum/ActualMaximum of the X axis in your Model (MyModel.Axes[0].ActualMinimum etc), perform the same operation as before but only for the interested points:
MyData.Select( p => p.Y && p.X > myMin && p.X < myMax).Max();
I haven't tested the code above, but should be enough to point you in the right direction.

Good luck

aoi wrote at 2014-05-21 09:52:

Thanks, the operation can find the max point in the ViewPort.
Further, if there are two or more lines in the ViewPort, I need to run the operation specific times to get the max point of these lines. Have any methods to make the "MyData" cover all the points in different lines in the ViewPort?

everytimer wrote at 2014-05-21 11:22:

MyData in my example is a collection of points. You can loop for each of your LineSeries if you don't want/can't use the "source" data of that LineSeries:
List<string> names = new List<string>();
List<double> maxima = new List<double>();
foreach(LineSeries ls in MyModel.Series.OfType<LineSeries>())
{
    double max = ls.Points.Select( p => p.Y && p.X > myMin && p.X < myMax).Max();
    maxima.Add(max);
    names.Add(ls.Title);
}

//Show gathered maxima

for(int i=0; i<names.Count; i++)
{
    MessageBox.Show("Maximum of " + names[i] + " in the current view is " + maxima[i]);  
}
(Untested)

EDIT: I think the way of obtaining the maximum of a range is not correct (you wont be able to compile that), you can select the range using .Where from Linq namespace.

var range = MyData.Where(p => p.X > MyMin && p.X < MyMax);
double max = range.Select( p => p.Y).Max();
Good luck

aoi wrote at 2014-05-21 11:53:

Thank you very much for helping me solve this problem with patience.That solved the problem.