Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

78
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda