How can I change the unit at y axis dynamically at Highcharts?
I have a formatter for y axis:
yAxis:{
title:{
text:'Custom Title'
},
labels: {
formatter: function () {
var maxElement;//I want to set it to max value at y axis labels
if(maxElement > gb){
return (this.value / gb).toFixed(1) + " GB";
}else if(maxElement > mb){
return (this.value / mb).toFixed(1) + " MB";
}else if(maxElement > kb){
return (this.value / kb).toFixed(1) + " KB";
} else {
return (this.value) + " B";
}
}
},
...
I asked a question here: How can I get the max value of a y axis at highcharts? about how to get the max value at y axis labels. However I think I should have sth like beforeLoad and beforeRedraw methods.
How can I change dynamically units of y axis labels (because if you disable/close series at right side max y axis label changes)?
Other solutions about my problem is welcome.
This case you can get the max
by the following line:this.axis.max;
So your function should be:
formatter: function() {
var maxElement = this.axis.max;
if (maxElement > gb) {
return (this.value / gb).toFixed(1) + " GB";
} else if (maxElement > mb) {
return (this.value / mb).toFixed(1) + " MB";
} else if (maxElement > kb) {
return (this.value / kb).toFixed(1) + " KB";
} else {
return (this.value) + " B";
}
}
You can see it working here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With