[Chartjs]-Chart.js update bars of a bar-chart

5👍

In general, you want to go through your data object, add,delete or replace your elements and then call .update , that’s it.

Here’s an example where I add 2 more columns at the end of a chart:

function addData() {
  myBarChart.data.labels[12] ="2017";
  myBarChart.data.labels[13] ="2018";
  myBarChart.data.datasets[0].data[12] = 500;
  myBarChart.data.datasets[0].data[13] = 600;
  myBarChart.update();
}

And more specifically to your case, here I modify the value of one year:

function adjust2016() {
  myBarChart.data.datasets[0].data[11] = 300;
  myBarChart.update();
}

Full Example:

Codepen Chart.js Add replace data example

Leave a comment