D3. thousands separator format for variables?

Hello, I'm stuck on d3 again ...

I would like to know how to use a thousand seperator for a variable, all the examples that I managed to find seem to be on static data.

This is what I have tried so far:

d3.csv("OrderValueToday.csv", function(obj) { 

var text = 'Today = £';
var totalSales = text + d3.format(",") + obj[0].Today;

svgLabel = d3.select("#label").append("h2")
 .text (totalSales);

});

However, it simply displays the load on the web page:

Today = £function (n){var e=d;if(m&&n%1)return"";var u=0>n||0===n&&0>1/n?(n=-n,"-"):a;    if(0>p){var c=Zo.formatPrefix(n,h);n=c.scale(n),e=c.symbol+d}else n*=p;n=g(n,h);var x=n.lastIndexOf("."),M=0>x?n:n.substring(0,x),_=0>x?"":t+n.substring(x+1);!s&&f&&(M=i(M));var b=v.length+M.length+_.length+(y?0:u.length),w=l>b?new Array(b=l-b+1).join(r):"";return y&&(M=i(w+M)),u+=v,n=M+_,("<"===o?u+n+w:">"===o?w+u+n:"^"===o?w.substring(0,b>>=1)+u+n+w.substring(b):u+(y?n:w+n))+e}20000

So, all I want is to make totalSalesthousands of delimiters matter, so 20,000all I tried does nothing. I read this https://github.com/mbostock/d3/wiki/Formatting but did not see what I can do for my script.

Any help would be greatly appreciated. Greetings

+4
source share
1 answer

d3.format , , , :

var myNumber = 22400;
d3.format(',')(myNumber); // returns '22,400'

, :

var commaFormat = d3.format(',');
commaFormat(1234567); // returns '1,234,567'

:

var totalSales = text + d3.format(',')(obj[0].Today);
+6

All Articles