Chartjs-How to assign values to different lables(legends) of my dataset of stacked bar chart

0👍

You have to loop through your data. My solutions works when your status always come in the same order (like they do in your example). If not, then you have to perform an additional check.

https://jsbin.com/zunimifidi/1/edit?js,output

chartData.labels = Object.keys(data)

for (let i = 0; i < status.length; i++) {
  console.log(status[i])
  let newDataset = {}
  newDataset.label = status[i]
  newDataset.backgroundColor = colors[status[i]]
  newDataset.data = []
  for (let idx in data) {  
    let cData = data[idx]
    newDataset.data.push(cData[i].count)
  }
  chartData.datasets.push(newDataset)
}

Leave a comment