gpt4 book ai didi

javascript - 用 D3 中轴上的逗号替换小数点?

转载 作者:行者123 更新时间:2023-11-29 16:57:20 25 4
gpt4 key购买 nike

这是关于 D3 中轴上的刻度:有没有办法用数字中的逗号替换小数点?我希望数字这样显示(这在德国很正常,这么大的数字只是为了演示)

1.000.000,1 // This is one million and a tenth

不是这样的:

1,000,000.1

我读过 documentation关于这个话题,但似乎没有可能!?到目前为止,这是我的相关代码:

localeFormatter = d3.locale({
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["", "€"],
"dateTime": "%a, %e %b %Y, %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["", ""],
"days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
"shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
"months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
"shortMonths": ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"]
});


numberFormat = localeFormatter.numberFormat("04.,"); // The setting is applied, but has not the desired effect...

yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(numberFormat);

最佳答案

d3.locale 使用以下设置:

var localeFormatter = d3.locale({
"decimal": ",",
"thousands": ".",
...
});

请注意,我已经更改了 , 中的 .,反之亦然。并且:

var numberFormat = localeFormatter.numberFormat(",.2f"); 

我使用千位分隔符 ,(它使用区域设置中定义的 .)和逗号后的两位数 .2f:

console.log(numberFormat(1000000.1)); // "1.000.000,10"

关于javascript - 用 D3 中轴上的逗号替换小数点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31269367/

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