Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda