Group Bar Chart Dinamic Data Update By Button Fuction ChartJS

0👍

You’re updating each dataset, and feeding it’s data with the new dataset. Also, the labels should also be provided on the chart itself, instead of the dataset items.

The correct way would be

function changeData(index) {
    var data = dataObject[index];
    chart.data.labels = data.label;
    chart.data.datasets = data.datachart;
    chart.update();
}

https://jsfiddle.net/8kzoc6nb/

👍:0

function changeData7(index) {
  chart7.data.datasets.forEach(function(item, indexs) {
    item.label = dataObject[index].datachart[indexs].label;
    item.data = dataObject[index].datachart[indexs].data;
  });
  chart7.update();
}

I do this but if i call changeData7(0), data doesnt change to index 0

Leave a comment