[Chartjs]-AddData() dropped from latest chart.js 2.1.3 – whats up?

4πŸ‘

βœ…

The update() handles adding data too. Just push your new data / labels into the config object that you passed when creating the chart and then call update()

For instance,

var config = {
  type: 'line',
  data: {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
      label: "My First dataset",
      data: [65, 0, 80, 81, 56, 85, 40],
      fill: false
    }]
  }
};

var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, config);

setTimeout(function(){
    config.data.labels.push('Test');
    config.data.datasets[0].data.push(3);
    myChart.update();
}, 1000);

Fiddle – http://jsfiddle.net/zpnx8ppb/

Leave a comment