基于新的(德国)语言环境设置时间轴标签的正确方法是什么?
我想将其与vega lite API一起使用。
这是我尝试过的:
vl1 = {
embed.vega.timeFormatLocale(locale); // show dates in German
embed.vega.formatLocale(locale); // show numbers with German groupings/ separators
const plot = vl.markBar()
.config({padding: {"left": 5, "top": 10, "right": 50, "bottom": 40}}) // now tooltip will not be clipped
.data(cdata_lk_vl)
.encode(
vl.x().fieldT('Datum').axis({"format": "%d. %B"}),
vl.y().fieldQ('infizierte Personen'),
vl.tooltip([
{"field": "Datum", "type": "temporal", "format": "%d. %B"}, // now date will be shown formatted
{"field": 'infizierte Personen', "type": "quantitative", "format": ","},
]))
return plot.render();
}
这似乎可行-有时!?。在过去的两个月中,与今天一样有几天,格式切换回默认的US_EN
我真的很想知道,a)这样做的正确方法是什么,b)为什么有时我的解决方案有时无法工作(无需更改代码)
答案 0 :(得分:2)
我给您发送了一个suggestion on Observable,但是我认为问题是因为您正在设置从vegaEmbed获得的vega
实例的语言环境。而是直接在vega
上有一个vl
实例。我认为通常,根据加载顺序,它们是完全相同的实例,但有时可以不同。
所以你想要
vl.vega.timeFormatLocale(locale); // show dates in German
vl.vega.formatLocale(locale); // show numbers with German groupings/ separators