12

Data for my Y axis (each country) has figures in millions:

{
  date: "1960",
  germany: "72542990",
  spain: "30327000",
  france: "46621166",
  italy: "50025500"
}

How do I write the .tickFormat(d3.format("")); on my Y axis variable to format the tick values so they show up in the Y axis scale like this: 0, 20 million, 40 million, 60 million, 80 million

Currently they show up as 0, 20000000, 40000000, 60000000,80000000

Thanks.

Raviteja
  • 3,399
  • 23
  • 42
  • 69
NewToJS
  • 2,011
  • 4
  • 35
  • 62

1 Answers1

33

Declare Formatter

formatValue = d3.format(".2s");

Use inside TickFormat

.tickFormat(function(d) { return formatValue(d)});

to replace M with million try this..

.tickFormat(function(d) { return formatValue(d).replace('M', 'million'); });
sam
  • 2,426
  • 2
  • 20
  • 29
  • Thanks and do you know how to make it say "million" instead of M ? – NewToJS Nov 11 '13 at 16:58
  • thanks again! also how I take the number out two decimals? like: 80.00 milllion OR 80.00M? – NewToJS Nov 12 '13 at 11:13
  • 2
    do you know where is this `.2s` format documented? Thanks! – Bruno Mar 07 '16 at 16:26
  • 2
    @ibiza https://github.com/d3/d3-format/blob/master/README.md#format It explains well about `.2s` and https://github.com/d3/d3-format/blob/master/README.md#locale_formatPrefix for formatPrefix – sam Jul 05 '16 at 08:10
  • 3
    Do you know if its possible to do this same replace method but with the python version of plotly? – FrankMank1 Jun 24 '20 at 04:46