I'm using d3.js for charts and now would like to update it to v4.
It was found that d3.locale()
doesn't work anymore since the translation all date formats are on different language.
How can I fix that? I'm digging the forum, but for v4 I didn't really find it.
I'm using d3.js for charts and now would like to update it to v4.
It was found that d3.locale()
doesn't work anymore since the translation all date formats are on different language.
How can I fix that? I'm digging the forum, but for v4 I didn't really find it.
Share Improve this question edited Sep 21, 2016 at 18:41 jjmontes 26.9k5 gold badges44 silver badges52 bronze badges asked Sep 21, 2016 at 17:47 BampBamp 1111 silver badge3 bronze badges 1- 1 could you add part of the code? the wiki of this project is very complete, github.com/d3/d3/wiki but if you add some code we could see which is your specific problem. – Fabrizio Migotto Commented Sep 21, 2016 at 18:15
3 Answers
Reset to default 16You have to use d3.timeFormatDefaultLocale(definition)
in d3 V4.
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"]
})
You can use
d3.formatLocale(definition)
or d3.formatDefaultLocale(definition)
have a look at this documentation https://devdocs.io/d3~4/d3-format#formatDefaultLocale
Looks like you want d3-time-format
here
https://github.com/d3/d3/blob/master/API.md