I'm using d3.js for charts and now would like to update it to v4.
我正在使用d3.js作为图表,现在想将其更新为v4。
It was found that d3.locale()
doesn't work anymore since the translation all date formats are on different language.
发现d3.locale()不再起作用,因为翻译所有日期格式都使用不同的语言。
How can I fix that? I'm digging the forum, but for v4 I didn't really find it.
我该如何解决这个问题?我正在挖掘论坛,但是对于v4,我并没有真正找到它。
2 个解决方案
#1
5
You have to use d3.timeFormatDefaultLocale(definition)
in d3 V4.
您必须在d3 V4中使用d3.timeFormatDefaultLocale(定义)。
Here is an example for German days and months:
以下是德国日期和月份的示例:
d3.timeFormatDefaultLocale({
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["€", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"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", "Dez"]
})
#2
-1
Looks like you want d3-time-format
here
看起来你想要d3时间格式
https://github.com/d3/d3/blob/master/API.md
https://github.com/d3/d3/blob/master/API.md
#1
5
You have to use d3.timeFormatDefaultLocale(definition)
in d3 V4.
您必须在d3 V4中使用d3.timeFormatDefaultLocale(定义)。
Here is an example for German days and months:
以下是德国日期和月份的示例:
d3.timeFormatDefaultLocale({
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["€", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"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", "Dez"]
})
#2
-1
Looks like you want d3-time-format
here
看起来你想要d3时间格式
https://github.com/d3/d3/blob/master/API.md
https://github.com/d3/d3/blob/master/API.md