gpt4 book ai didi

d3.js - 格式化Y轴值,原始数字以百万为单位,只想显示前三位

转载 作者:行者123 更新时间:2023-12-04 02:40:46 43 4
gpt4 key购买 nike

我的 Y 轴(每个国家/地区)的数据以百万计:

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

我该怎么写 .tickFormat(d3.format(""));在我的 Y 轴变量上格式化刻度值,以便它们显示在 Y 轴刻度中,如下所示:
0、2000万、4000万、6000万、8000万

目前他们显示为
0、20000000、40000000、60000000、80000000

谢谢。

最佳答案

声明格式化程序

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

在 TickFormat 中使用
.tickFormat(function(d) { return formatValue(d)});

用百万替换 M 试试这个..
.tickFormat(function(d) { return formatValue(d).replace('M', 'million'); });

关于d3.js - 格式化Y轴值,原始数字以百万为单位,只想显示前三位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19907206/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com