Is it possible to change the axis title of a HighCharts chart programatically?
I'm trying to do something like this:
charts.series[0].yAxis.title.text = 'new title';
or
charts.yAxis[0].title.text = 'new title';
(having already set a title when the chart was initialized).
This can be done directly on the
Axis
object usingsetTitle
now. For example:See this JSFiddle demonstration. The method signature is:
So you could optionally pass a boolean to wait with redrawing. The
title
object takes the same parameters asxAxis.title
meaning you could pass in styles and several other options as well as the text itself. The API documentation has the complete information.I couldn't get either of the above to work, perhaps things have changed since last year... I ended up using:
and it worked nicely...
The above answer has still one problem. Images created from the plot using the export module will show the original title, not the changed one. Add the following line to fix:
Yes you can do this by using the following:
I have created a demo fiddle to dynamically change y-axis title. Refer this JSFIDDLE
HTML:
JS (part of thec code to update the y-axis title on a button click):
Refer Highcharts 'update' function documentation for further details.