How to fill my chart (chart.js) with my own data from API

๐Ÿ‘:0

you need to push them into labels and data in a for loop. i recommend a for of loop
simple like this

axios.get("localhost:3000/piechart").then(
  (response) => {
    console.log(response.data);
    for (const item of piechart) {
      getPieChartData.labels.push(item.category);
      getPieChartData.datasets[0].data.push(item.total);
    }
  },
  (error) => {
    console.log(error);
  }
);

Leave a comment