[Chartjs]-Is there any method to map or represent API data to Chart in ReactJS?

1👍

Data seems to be an array of objects, the structure you mention to be the API data. In that case, this data must be mapped to individual arrays in order to obtain data.labels and the data of the unique dataset.

This could be done as follows:

const data = {
  labels: Data.map(o => o.date), // first change
  datasets: [{
    label: 'XNA/AUD',
    fill: false,
    lineTension: 0.0,
    backgroundColor: 'rgb(41, 33, 116,0.5)',
    borderColor: 'rgb(41, 33, 116,0.5)',
    pointHitRadius: 20,
    data: Data.map(o => parseFloat(o.xnaaud)) // second change
  }]
};

Leave a comment