I would like to get y point from a given x point. x point will not necesary be a point in chart, it can be between two points. x point is a constant value, so is not clicked or seleted
In my case the given points for draw the graph are the red ones , but i would like to get green one knowing x value
You can loop through points and try to find the one by searching x value. If the point is not found, calculate y value based on the next and the previous ones. The below algorithm should work fine for line series:
const x = 3;
const chart = Highcharts.chart('container', {...});
const points = chart.series[0].points;
let prevX, nextX;
let prevY, nextY;
let y;
points.forEach((point, index) => {
if (point.x === x) {
y = point.y;
}
if (point.x > x && !prevX) {
nextX = point.x;
prevX = points[index - 1].x;
nextY = point.y;
prevY = points[index - 1].y;
}
});
if (!y) {
const xDiff = nextX - prevX;
const yDiff = nextY - prevY;
const unit = yDiff / xDiff;
y = (x - prevX) * unit + prevY;
}
console.log(y);
Live demo: http://jsfiddle.net/BlackLabel/uavrmLhk/