【问题标题】:How to stop nvd3 angular directives from rounding off values?如何阻止 nvd3 角度指令舍入值?
【发布时间】:2016-06-29 12:12:47
【问题描述】:

nvd3-angular-directives 饼图在显示百分比时会四舍五入。有没有办法用小数位精确显示?我有 99.71% 和 0.29% 的值,它们四舍五入为 100% 和 0%。

...
<nvd3-pie-chart
        data="scenarioPie"
        id="scenarioPie"
        width="450"
        height="450"
        x="xFunction()"
        y="yFunction()"
        donut="true"
        tooltips="true"
        showLabels="true"
        donutLabelsOutside="true"
        labelType="percent"
        showLegend="true"
        donutRatio=".4">
<svg></svg>
...

我尝试使用如下函数返回格式,但它不起作用

...
labelType="myFunction()"
...

$scope.myFunction=function() {
  return function(d){
    return d3.format(',.2%');
  }
}

【问题讨论】:

    标签: angularjs-nvd3-directives


    【解决方案1】:
    $scope.xFunction = function(){ return function(d){ return d3.format('.02f')(d.x); }; };
    

    【讨论】:

    • 欢迎来到 Stack Overflow,Aadesh,感谢您的回答,但请添加一些文字来解释您的代码究竟做了什么。
    • 欢迎来到 Stack Overflow!尽管此代码可能有助于解决问题,但它并没有解释 why 和/或 如何 回答问题。提供这种额外的背景将显着提高其长期教育价值。请edit您的答案添加解释,包括适用的限制和假设。
    猜你喜欢
    • 2016-11-30
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    相关资源
    最近更新 更多