Javascript Highcharts:Y轴标签格式化程序

Javascript Highcharts:Y轴标签格式化程序,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我有一个y轴标签格式化程序 yAxis: { title: { text: null }, labels: { formatter: function(){ return (Math.abs(this.value) / 1000000) + 'M'; }

我有一个y轴标签格式化程序

        yAxis: {
            title: {
                text: null
            },
            labels: {
                formatter: function(){
                    return (Math.abs(this.value) / 1000000) + 'M';
                }
            }
        },
但是我需要格式化程序检查值是否超过1000000,然后相应地格式化。。 我试过了,但效果不好

        yAxis: {
            title: {
                text: null
            },
            labels: {
                formatter: function(){
                    if (this.value > 999999) {
                    return (Math.abs(this.value) / 1000000) + 'M';};
                }
            }
        },
它仅在一侧显示标签。。 我正在使用堆叠条形图金字塔

这是在JSFIDLE上的


问题在于,格式化程序函数仅在值大于或等于100万时返回标签。您需要在此比较中使用绝对值,并将
return
语句移到
if
块之外:

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

问题是formatter函数仅在值大于或等于100万时返回标签。您需要在此比较中使用绝对值,并将
return
语句移到
if
块之外:

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

好的,谢谢,我知道了。。我不知道为什么我没有注意到负数。。再次谢谢,谢谢,我知道了。。我不知道为什么我没有注意到负数。。再次感谢