简体   繁体   English

高图:Y轴标签格式化程序

[英]Highcharts: Y axis label formatter

I have this y axis labels formatter 我有这个y轴标签格式化程序

        yAxis: {
            title: {
                text: null
            },
            labels: {
                formatter: function(){
                    return (Math.abs(this.value) / 1000000) + 'M';
                }
            }
        },

but I need the formater to check if the values is more than million 1000000 then format it accordingly.. I've tried this but it didn't work properly 但是我需要格式化程序来检查值是否大于百万1000000,然后对其进行相应的格式化。.我已经尝试过了,但是工作不正常

        yAxis: {
            title: {
                text: null
            },
            labels: {
                formatter: function(){
                    if (this.value > 999999) {
                    return (Math.abs(this.value) / 1000000) + 'M';};
                }
            }
        },

it displayed the labels on one side only.. I'm using the Stacked bar chart pyramid 它只在一侧显示标签。.我在使用堆积条形图金字塔

here is it on JSFiddle 这是在JSFiddle上

http://jsfiddle.net/chGkK/ http://jsfiddle.net/chGkK/

The issue is the formatter function only returns a label if the value is greater or equal to 1 million. 问题是格式化程序函数仅在值大于或等于100万时才返回标签。 You need to use the absolute value in this comparison and move the return statement outside the if block: 您需要在此比较中使用绝对值,并将return语句移至if块之外:

var absValue = Math.abs(this.value);
if (absValue >= 1000000) {
  absValue = (absValue / 1000000) + 'M';
};
return absValue;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM