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.

4

1 に答える 1

33

フォーマッターの宣言

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

TickFormat 内で使用

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

Mを百万に置き換えるには、これを試してください..

.tickFormat(function(d) { return formatValue(d).replace('M', 'million'); });
于 2013-11-11T14:19:53.290 に答える