如何在Highcharts动态地改变y轴的单位? [英] How can I change the unit at y axis dynamically at Highcharts?

查看:1222
本文介绍了如何在Highcharts动态地改变y轴的单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个用于y轴的格式化程序:

  yAxis:{
title:{
text:'自定义标题'
},
标签:{
formatter:function(){
var maxElement; //我想将它设置为y轴标签处的最大值

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;
}
}
},
...

我在这里问了一个问题:如何在y轴标签上获取最大值,如何获得y轴的最大值?然而,我认为我应该像beforeLoad和beforeRedraw方法那样。



如何动态更改y轴标签的单位(因为如果您禁用/关闭系列在右侧max y轴标签变化)?

有关我的问题的其他解决方案是值得欢迎的。 解决方案

这种情况下,您可以通过以下行获取 max

this.axis.max; code

所以你的函数应该是:


  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;


$ / code>

你可以看到 在这里工作


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.

这篇关于如何在Highcharts动态地改变y轴的单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆