【问题标题】:How to display one million in dimple measure axis as 1000k instead of 1m?如何将一百万的凹坑测量轴显示为 1000k 而不是 1m?
【发布时间】:2017-03-01 12:03:04
【问题描述】:

我们使用dimpleJs 在图表的y 轴上显示价格值。当价格超过100万时,在图表中显示时自动转换为1m。我希望以数千或十万/数十万的形式显示数百万,请参阅Indian Numbering System。怎么做?我已经搜索并尝试过this 答案 但它似乎不起作用。下面是我的代码sn-p:

const yAxis = chart.addMeasureAxis('y', 'total');
yAxis.tickFormat = function(d) {
  let result = d;
  if ((d / 1000) >= 1) {
    result = d / 1000 + 'K';
  }
  return result;
};

【问题讨论】:

    标签: javascript d3.js dimple.js


    【解决方案1】:

    看看 johnkiernander 在这个线程上的回答:https://github.com/ramnathv/rCharts/issues/421

    Dimple 只是将一个字符串传递给 d3.js 的 format 函数,所以你不能将函数传递给 tickformat,你应该可以像这样覆盖 _getformat 函数:

      yAxis._getFormat = function() {
        return function(d) {
          let result = d;
          if ((d / 1000) >= 1) {
            result = d / 1000 + 'K';
          }
          return result;
        };
      };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-11
      相关资源
      最近更新 更多