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

82
Visualizações
How to fetch data into Victory Native Charts

I am using victory native chart to render area chart and i dont know how to fetch data from api to the chart, meaning x will hold "usia" and y will hold "indeks_massa". anyone good people can help me to solve this? :(

this is my code:

const data = listHistory.map((usia, indeks_massa) => {
    return { x: usia, y: indeks_massa }
})
<VictoryLine style={{ data: { stroke: "blue" }, }}
             data={data}
/>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Well, you'll need to get the data, set state with it, and update the component with some additional information - at least based on their documentation. If you need to manipulate the data you can do that before you add it to state.

const { useEffect, useState } = React;

// Transforms the data
function mappedData(data) {
  return data.map((el, index) => {
    return { x: el, y: index };
  });
}

function Example() {

  const [ data, setData ] = useState([]);

  // Run `getData` once (the empty dependency array
  // `[]` ensures that). `getData` fetches the JSON,
  // and parses it, and then `setData` adds the (now
  // transformed data to state.
  useEffect(() => {
    async function getData() {
      const response = await fetch(<endpoint>);
      const data = await response.json();
      setData(mappedData(data));
    }
    getData();
  }, []);

  return (
    <VictoryBar
      data={data}
      x="x"
      y="x"
    />
  );

}

ReactDOM.render(
  <Example />,
  document.getElementById('react')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
<div id="react"></div>

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