Chartjs-How to update only new data in Chart.JS?

0👍

Yes you can update both things

  1. New label with new data point
  2. update exisiting datapoint

    document.getElementById('addData').addEventListener('click', function() {
            if (config.data.datasets.length > 0) {
                var month = MONTHS[config.data.labels.length % MONTHS.length];
                config.data.labels.push(month);
    
                config.data.datasets.forEach(function(dataset) {
                    dataset.data.push(randomScalingFactor());
                });
    
                window.myLine.update();
            }
        });
                document.getElementById('updateOnlyPoint').addEventListener('click', function() {
            if (config.data.datasets.length > 0) {
                var month = config.data.labels.indexOf("March");//change point
                var olddata=config.data.datasets[0].data
                 olddata[month]=randomScalingFactor(); //new data
                window.myLine.update();
            }
        });
    

here is working example

Leave a comment