格式Y轴值,原始数字以百万计,只想显示前三位数 [英] Format Y axis values, original figures in millions, only want to show first three digits

查看:135
本文介绍了格式Y轴值,原始数字以百万计,只想显示前三位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Y轴资料(每个国家/地区)都有数百万的资料:
{date:1960,
germany:72542990,
spain:30327000,
france:46621166,
italy:50025500}

Data for my Y axis (each country) has figures in millions: {date: "1960", germany:"72542990", spain: "30327000", france: "46621166", italy: "50025500"}

如何写.tickFormat(d3.format(在我的Y轴变量上格式化刻度值,以便它们在Y轴刻度上显示如下:
0,2000万,4000万,6000万,8000万

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

目前他们显示为
0,20000000,40000000,600000,80000000

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

感谢。

推荐答案

声明格式化程序

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

在TickFormat中使用

Use inside TickFormat

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

以百万美元替换M尝试这个..

to replace M with million try this..

.tickFormat(function(d) { return formatValue(d).replace('M', 'million'); });

这篇关于格式Y轴值,原始数字以百万计,只想显示前三位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆