How to remove Decimals in nvd3.js charts?
2 answers
You need to override the valueFormat of the chart, for example:
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.valueFormat(d3.format(".0f"))
.showLabels(true);
d3.select("#chart svg")
.datum(data)
.transition().duration(1200)
.call(chart);
return chart;
});
Here .valueFormat(d3.format(".0f"))
means:
-
.0
: zero precision (the exact meaning of this depends on what type is used). -
f
: a type; in this case Number.toFixed . This means that a fixed number of digits (precision) appear after the decimal point and the number is rounded if necessary.
+8
source to share