I would like to get the Y-value of a graph, corresponding to an X-value given as input.
Noting that the given X-value may not necessarily be within the input table of X versus Y values, meaning that some kind of interpolation may be needed to compute the Y-value, is there a SciChart API for getting this Y-value corresponding to a given X-value? Rather than me performing the interpolation through code. Thanks.
- Amarnath S asked 2 years ago
- You must login to post comments
Hi Amarnath
There’s a couple of things to consider here to give you a good answer.
If you’re trying to find the y-value of a series (see attached image), then do this
- Iterate through the dataseries.XValues to find the index nearest the x-value, or use dataSeries.FindIndex()
- Now get the y-value at that index by getting dataSeries.YValues[i]
If you’re trying to do it based on a x-coordinate (not x-value) then I suggest using the Hit-Test API. Specifically RenderableSeries.HitTestProvider.VerticalSliceHitTest provides an X-First method of searching for y-values.
Which one of those sounds right for you? Do they answer your question?
Best regards,
Andrew
- Andrew Burnett-Thompson answered 2 years ago
-
XYDataSeries does not have a HitTestProvider property to be able to use the VerticalSliceHitTest() method. Any other suggestions.
-
Hi Patric, HitTestProvider is on the RenderableSeries. The Data (XyDataSeries) may be rendered differently for scatter, line, mountain charts, hence you need to use FastLineRenderableSeries.HitTestProvider.HitTest(). Take a look at our hit-test docs for more info. https://www.scichart.com/documentation/js/current/webframe.html#Hit-Test%20API.html
- You must login to post comments
Yes. It does. Thanks a lot.
Somehow the nearest neighbour method slipped from my mind. Thanks once again.
- Amarnath S answered 2 years ago
- You must login to post comments
As a follow up to this question I have the same question but the answer is not clear to me. I am using the FindIndex(_cursor1Date, SearchMode.RoundDown) method on an XYDataSeries for a given x data value as defined by a cursor position on the chart.
The index I receive is the nearest index rounded down and when I use that index on the yValues I am not receiving the data point at the specified x data value but the nearest sampled value correct?
Like the original poster mentioned, I would have to do the same interpolation as the chart to get the actual value between two data samples like the chart draws.
Note, I am setting the IsDigitalLine property to false and the XYDataSeries does not have a HitTestProvider property to be able to use the VerticalSliceHitTest() method.
- patrick milinazzo answered 2 years ago
- last edited 2 years ago
-
Hi Patrick, the format of the forum is 1 question multi answer and the answers can be re-ordered with votes. Can you create a new question with what you’re trying to achieve, code used so far, expected vs. actual result? We will take a look. Note the HitTestProvider property is on RenderableSeries (see https://www.scichart.com/documentation/js/current/webframe.html#Hit-Test%20API.html) Best regards, Andrew
- You must login to post comments
Please login first to submit.