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

114
Visualizações
Updating yaxis min/max bounds in an apexchart series

I'm using apexcharts and react to model a live updating price chart. As part of this chart, I would like to update the minimum and maximum bounds as new data from the series is rendered.

My thoughts are that I can define state for min and max bounds,

  let [min, setMin] = useState(9999)
  let [max, setMax] = useState(0)

set the state inside apexcharts updated event option (which fires when the chart has been dynamically updated either with updateOptions() or updateSeries() functions) when the latest price from the series is above or below the current min/max.

  const options = {
      events: {
        updated: function(chartContext, config) {
          console.log(`update called! \n chartContext: ${chartContext.data.twoDSeries}`)
          let yaxis = config.config.yaxis[0]
          let latestPrice = chartContext.data.twoDSeries[chartContext.data.twoDSeries.length - 1]
          if(yaxis.min > latestPrice){
            setMin(latestPrice)
          }
          if(yaxis.max < latestPrice) {
            setMax(latestPrice)
          }
        }
      }
    },

and then plug in the min/max values into the yaxis option and return the chart

    yaxis: {
      title: { text: "Live updating chart" },
      labels: {
        formatter: val => val.toFixed(1)
      },
      min: min,
      max: max
    }
  };
  return <Chart type="candlestick" options={options} series={props.dataList} width = "1200" height = "600" />;
};

However this doesn't work very well and the updated state is not reliably getting passed to the y-axis. Is there a better way to do this? Thanks!

about 4 years ago · Santiago Trujillo
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