最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to display highchart y axis with constistant data - Stack Overflow

programmeradmin3浏览0评论

I have a highchart column graph, in that at some time the y axis data are displaying as [1000,2000,3000,4000] and some times as [1k, 2k, 3k, 4k].

How can I fix it to single type of data.

Regards, Navin Leon

I have a highchart column graph, in that at some time the y axis data are displaying as [1000,2000,3000,4000] and some times as [1k, 2k, 3k, 4k].

How can I fix it to single type of data.

Regards, Navin Leon

Share Improve this question asked Feb 29, 2012 at 19:53 Navin LeonNavin Leon 1,1665 gold badges22 silver badges45 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 11

Compare http://jsfiddle.net/BNFe5/

The difference is here:

yAxis: {
    labels: {
        formatter: function() {
            return this.value;
        }
    }
},

For Converting your yaxis values into 1k,2k,3k,4k,etc:

yAxis: 
{
    labels: 
    { 
      formatter: function() 
      {
         return Math.round(this.value/1000) + 'k';
      }
    }
},

If you are using thousands and millions in one chart, check this out.

yAxis: {
    labels: {
        formatter: function () {
            if (this.value.toFixed(0) >= 1000000) {
                return '$' + this.value.toFixed(0) / 1000000 + 'M';
            } else {
                return '$' + this.value.toFixed(0) / 1000 + 'K';
            }
        }
    },
    title: {
        text: ''
    }
},
发布评论

评论列表(0)

  1. 暂无评论