Chartjs-How to make interactive a chart with chart.js

1👍

You can just use the function in the documentation page, you have to pass the chart, label and data.

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

if you need to remove previous data

function removeData(chart) {
    chart.data.labels.pop();
    chart.data.datasets.forEach((dataset) => {
        dataset.data.pop();
    });
    chart.update();
}

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

Leave a comment