[Chartjs]-Ionic 3 Angular Chart.js update data

2👍

As mentioned in the Chart.js documentation, you need to call chart.update() if you wish to update the data in your chart after it was created:

http://www.chartjs.org/docs/latest/developers/updates.html

Example of adding data and then updating the chart:

function addData(chart, label, data) {
    chart.data.labels.push(label);
    chart.data.datasets.forEach((dataset) => {
        dataset.data.push(data);
    });
    chart.update();
}

After you finish changing the data in your update function, you just need to add the update line of code like the following:

this.pepsiData[3] = 80;
myChart.update();

Leave a comment