How to remove Decimals in nvd3.js charts?
I am using nvd3.js to create a pie chart, I was trying to find a way to remove the decimal point, for example 2.00 in 2. in legends.
How can i do this?
thank
+3
jjmarttinjjmartinez
source
to share
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
Osman Mazinov
source
to share
For nied3, the valueFormat: pie chart d3.format("0f")
, this will work correctly.
0
rohit parte
source
to share