Skip to content

Instantly share code, notes, and snippets.

@woolfg
Last active September 25, 2023 12:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woolfg/50b1ee17c8e4aa4c8a92 to your computer and use it in GitHub Desktop.
Save woolfg/50b1ee17c8e4aa4c8a92 to your computer and use it in GitHub Desktop.
d3.js german locale - create time scale axis with german locale
var germanFormatters = d3.locale({
"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"]
});
var customTimeFormat = germanFormatters.timeFormat.multi([
[".%L", function(d) { return d.getMilliseconds(); }],
[":%S", function(d) { return d.getSeconds(); }],
["%I:%M", function(d) { return d.getMinutes(); }],
["%Hh", function(d) { return d.getHours(); }],
["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }],
["%b %d", function(d) { return d.getDate() != 1; }],
["%B", function(d) { return d.getMonth(); }],
["%Y", function() { return true; }]
]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickFormat(customTimeFormat);
@Hirse
Copy link

Hirse commented Apr 2, 2015

Note, this is Austrian German (de_at).

@Gotenks88
Copy link

it is not
Agu but Aug
thanks a lot!

@woolfg
Copy link
Author

woolfg commented Jan 15, 2020

changed to real DE locale and fixed typo ;) - thanks

@i-am-the-slime
Copy link

Januar only takes one n.

@woolfg
Copy link
Author

woolfg commented Aug 31, 2021

Januar only takes one n.

thanks @i-am-the-slime ... changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment