Pre loader

Getting Y-value corresponding to a given X-value

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

I am using a draggable VerticalLineAnnotation to let the user select a X value. Vertical Modifier is not an option due to terrible performance. I tried with the following code but is not returning the expected value, sometimes returns a wrong value and sometimes is returning Nan:

const index = dataSeries?.findIndex(targetX, ESearchMode.Nearest);
const yValue = dataSeries?.getNativeYValues()?.get(index);
Version
3.5.697
  • You must to post comments
0
0

Hi Jhonatan,

We tried to reproduce this but could not. I’ve created the codepen showing how to get the y-value to a corresponding x-value here.

Here’s my code.

After creating a FastLineRenderableSeries and XyDataSeries I use xyDataSeries.findIndex to find the nearest index to the xValue of 70. I then find the yValue that corresponds to this xValue:

// For the x-value at 70, find the Y-value
const xValue = 70;
const index = xyDataSeries.findIndex(xValue, ESearchMode.Nearest);
const yValue = xyDataSeries.getNativeYValues().get(index);

I also place some annotations onto the chart to show the intersection:

// Add an annotation to the line showing the X-Y intersection
sciChartSurface.annotations.add(new VerticalLineAnnotation({ 
    x1: xValue,
    y1: yValue,
    showLabel: true,
    strokeDashArray: [2, 2],
    stroke: "Orange"
}), new HorizontalLineAnnotation({
    x1: xValue,
    y1: yValue,
    showLabel: true,
    strokeDashArray: [2, 2],
    stroke: "Orange"
}));  

This results in the following output

Yvalue based on XValue

Other methods are possible in scichart, for example, how to get the Y-Value at a x-y mouse coordinate using the HitTest API.

Let me know if this helps

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.