【问题标题】:How to display highchart y axis with constistant data如何使用恒定数据显示高图表 y 轴
【发布时间】:2012-03-19 07:49:10
【问题描述】:

我有一个 highchart 柱形图,有时 y 轴数据显示为 [1000,2000,3000,4000],有时显示为 [1k, 2k, 3k, 4k]。

如何将其修复为单一类型的数据。

问候, 纳文·莱昂

【问题讨论】:

    标签: javascript jquery graph charts highcharts


    【解决方案1】:

    比较http://jsfiddle.net/BNFe5/

    区别就在这里:

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

    【讨论】:

    • 谢谢 Cheery,解决了我的问题。
    • 如果我想显示 K 值而不是数字,例如:而不是 [1000,2000] 如何显示 [1k,2k] ?有可能吗?
    • @NavinLeon 在formatter 函数中使用return Math.round(this.value/1000) + 'k';
    • 感谢@Cheery 我找到了 Highcharts.numberFormat(this.value/1000, 0) + "K"
    【解决方案2】:

    用于将 yaxis 值转换为 1k、2k、3k、4k 等:

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

    【讨论】:

      【解决方案3】:

      如果您在一张图表中使用数以百万计的数据,请检查一下。

      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: ''
          }
      },
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-31
        • 1970-01-01
        • 1970-01-01
        • 2022-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多