最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - d3.locale() in d3.js v4, localization - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

3 Answers 3

Reset to default 16

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"]
    })

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

发布评论

评论列表(0)

  1. 暂无评论