Chartjs-Chart js update multiple charts

0๐Ÿ‘

โœ…

If you have only two charts, you can just create two different Chart objects and work on individual charts by their objects.

ctx1 = document.getElementById("c1");
ctx2 = document.getElementById("c2");
myPieChart = new Chart(ctx, {
              type: 'pie',
              data: data1
            });
myLineChart = new Chart(ctx, {
              type: 'line',
              data: data1
            });

To dynamically add new data to an existing chart,

function updateChart(newData){
    var length = myLineChart.options.data[0].dataPoints.length;
    chart.options.data[0].dataPoints.push({ y: newData});
    chart.render();
}

Leave a comment