在我的代码的早期版本中,我曾经像这样设置适当的区域设置格式
format = {
"decimal": ".",
"thousands": "",
"grouping": [3],
"currency": ["€", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%d-%m-%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Domenica", "Lunedi", "Martedi", "Mercoledi", "Giovedi", "Venerdi", "Sabato"],
"shortDays": ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
"months": ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
"shortMonths": ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"]
}
进而
var localeFormatter = d3.locale(format);
// set time tick format
var tickFormat = localeFormatter.timeFormat.multi([
["%H:%M", function (d) { return d.getMinutes(); }],
["%H:%M", 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; }]
]);
我最终存储了这些刻度格式设置,以便我可以在图表中使用它们
D3Preferences['localTimeTickFormat'] = tickFormat;
更新到发布v4.2.8后d3.locale
已经消失了,我不知道如何达到相同的结果。
有人能指出我正确的方向吗? d3 文档对我没有帮助