Chartjs-How to change dynamically yAxes in chart.js

0👍

You can change the scale title simply by updating the labelString value in your chart object’s options property and calling the .update() prototype method.

Assuming I have a chart instance called myBar (the instance is what is returned from the Chart.js constructor), then I can use the below example to change the y-axes title.

myBar.options.scales.yAxes[0].scaleLabel.labelString = "My New Title";
myBar.update();

Here is a codepen that demonstrates a working example of this. Just click on the “Change Title” button to see if work.

Leave a comment