Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3.locale() in d3.js v4, localization

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.

like image 588
Bamp Avatar asked Sep 21 '16 17:09

Bamp


1 Answers

You 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"]
    })
like image 95
Simon Schneider Avatar answered Nov 03 '22 15:11

Simon Schneider