Format Y axis values, original figures in millions, only want to show first three digits

空扰寡人 提交于 2019-12-04 03:01:47

问题


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.


回答1:


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'); });


来源:https://stackoverflow.com/questions/19907206/format-y-axis-values-original-figures-in-millions-only-want-to-show-first-thre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!