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

89
Views
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 answers
Answer question

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 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!