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);
- Jhonatan Laguna asked 2 months ago
- last edited 2 months ago
- You must login to post comments
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
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
- Andrew Burnett-Thompson answered 2 months ago
- last edited 1 month ago
- You must login to post comments
Please login first to submit.