Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Get y point from x given point hightcharts

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

enter image description here

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!