1

I have this y axis labels formatter

        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

        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

http://jsfiddle.net/chGkK/

4

1 回答 1

1

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

var absValue = Math.abs(this.value);
if (absValue >= 1000000) {
  absValue = (absValue / 1000000) + 'M';
};
return absValue;
于 2013-04-27T00:55:06.850 回答