Hello.
Could you suggest me how I can find a nearest point (and X coordinate of this point) from all series by X coordinate?
It is need for drawing a LineSeriesCursors in a properly place.
Thanks.
- Andrey.
Nearest point by coordinates
Moderator: Queue Moderators
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Nearest point by coordinates
Hi Andrey,
You can use SolveYCoordAtXCoord for solving by screen coordinate, or SolveYValueAtXValue method for solving by given X value. Since you need Y value and nearest X value and not coordinates, i would recommend the follwing approach:
You can use SolveYCoordAtXCoord for solving by screen coordinate, or SolveYValueAtXValue method for solving by given X value. Since you need Y value and nearest X value and not coordinates, i would recommend the follwing approach:
Code: Select all
void m_chart_MouseMove(object sender, MouseEventArgs e)
{
foreach (PointLineSeries s in m_chart.ViewXY.PointLineSeries)
{
double xValue;
m_chart.ViewXY.XAxes[0].CoordToValue(e.X, out xValue, false);
LineSeriesValueSolveResult r = s.SolveYValueAtXValue(xValue);
double xNearest = s.Points[r.NearestDataPointIndex].X;
double yNearest = s.Points[r.NearestDataPointIndex].Y;
}
}
LightningChart Support Team, PT
-
- Posts: 29
- Joined: Fri Sep 04, 2015 2:30 pm
Re: Nearest point by coordinates
OK, but can I do something like this but for SampleDataSeries?
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Nearest point by coordinates
For SampleDataSeries it goes like this:
Code: Select all
void m_chart_MouseMove(object sender, MouseEventArgs e)
{
foreach (SampleDataSeries s in m_chart.ViewXY.SampleDataSeries)
{
double xValue;
m_chart.ViewXY.XAxes[0].CoordToValue(e.X, out xValue, false);
LineSeriesValueSolveResult r = s.SolveYValueAtXValue(xValue);
double xNearest = s.FirstSampleTimeStamp + (double) r.NearestDataPointIndex / s.SamplingFrequency;
double yNearest = s.SamplesDouble[r.NearestDataPointIndex];
}
}
LightningChart Support Team, PT