【问题标题】:Issue with nvd3 charts in angular 2. Unable to display y-axis values as desired角度 2 中的 nvd3 图表出现问题。无法根据需要显示 y 轴值
【发布时间】:2018-01-23 13:23:21
【问题描述】:

我正在使用 angular2 nvd3 图表。我在 y 轴上缩放时遇到问题。我有 y 值,例如 623.10、631.60、629.10、633.50、631.80、623.40 等,

并且在选项中正在做类似的事情

yAxis: {
    tickFormat: function(d) {
      return d3.format('f')(d);
    }
  }

它在图表中显示,如 623、624、625、626 等......我希望我的 y 轴值显示在图表中,如 620、630、640......我是新手。有人可以告诉我如何实现这一目标吗?

【问题讨论】:

    标签: angular nvd3.js angular-nvd3


    【解决方案1】:

    使用toFixed(0) 格式化您的数据:

    function format(d) {
      return d.toFixed(0);
    }
    
    console.log(format(631.60));
    // expected output: "631"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      相关资源
      最近更新 更多