how can I programmatically change the label of the Y axis in Chart.JS

Viewed 10

in Chart.JS (v3) - how can I programmatically change the label of the Y axis?

myChart.scales.y.text=yaxislabel;

...doesn't change it - although all of the rest of the datasets and labels updates ok with my code below:


$yaxislabel = 'kg';
myChart.data.datasets[0].data = Object.values(varsdata);
  myChart.data.labels= Object.values(varslabels);
  myChart.data.datasets[0].label = chartdatalabel;
  myChart.scales.y.text=yaxislabel;
  myChart.update();

Thanks, Mark

1 Answers

This is because you need to put it in the title namespace. So your statement must be: myChart.scales.y.title.text=yaxislabel;. For it to show up you also need to make sure it is enabled by calling: myChart.scales.y.title.display = true;

Related