Categories
JavaScript Answers

How to dynamically update values of a Chart.js chart with JavaScript?

Spread the love

Sometimes, we want to dynamically update values of a Chart.js chart with JavaScript.

In this article, we’ll look at how to dynamically update values of a Chart.js chart with JavaScript.

How to dynamically update values of a Chart.js chart with JavaScript?

To dynamically update values of a Chart.js chart with JavaScript, we set the data set value and update the chart.

For instance, we write

myBarChart.data.datasets[0].bars[2].value = 50;
myBarChart.update();

to set the value we want to update with

myBarChart.data.datasets[0].bars[2].value = 50;

Then we call update to update the chart.

Conclusion

To dynamically update values of a Chart.js chart with JavaScript, we set the data set value and update the chart.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *