How do I format the value shown in the d3 plot

I am trying to change the formatting to the value shown at the top of the histogram in the nvd3 discrete histogram. I believe that I am doing something wrong, I have no idea.

Here is the js script for the chart http://jsfiddle.net/looneydoodle/PdpRq/

Here is the code

var basicformat = d3.format(',f'); d3graph.selectAll('g.nv-bar text').each(function(d,i){ this.text(basicformat(this.value)); }); 

EDIT:

It turned out how to do it, although it might be a bad way to do it. Here is the updated fiddle: http://jsfiddle.net/looneydoodle/PdpRq/2/

+4
source share
1 answer

It appears that discreteBarChart has a valueFormat() method. You can define it in the nvd3 source on line 232.

So, to set a format other than the default one, all you need is:

 chart.valueFormat(d3.format('f'))// Or whatever format you'd like 

Here jsFiddle

+13
source

Source: https://habr.com/ru/post/1468814/


All Articles