如何根据德语区域设置时间轴标签(刻度)

How to set time axes labels (ticks) based on German locale

根据新的(德语)区域设置设置时间轴标签的正确方法是什么?

我想将它与 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();
}
  1. 我创建了一个可观察对象:https://observablehq.com/@ee2dev/coronavirus-in-bayern-teil-2 单元格 vl1 显示了我想要反映区域设置格式的图表。 根据 observable 论坛 https://talk.observablehq.com/t/changing-the-locale-for-vega-lite/3010 的建议,我实现了这个:

这似乎有效 - 有时!?。在过去的两个月里,有几天像今天一样,将格式切换回默认 US_EN

  1. 这里的相关问题 在这种情况下似乎没有帮助

我真的很想知道,a) 正确的方法是什么以及 b) 为什么我的解决方案有时会在其他时候不起作用(没有我更改代码)

我给你发了一个 suggestion on Observable,但我认为问题是因为你在从 vegaEmbed 获得的 vega 实例上设置了语言环境。相反,vl 上直接有一个 vega 实例。我经常认为,根据加载顺序,它们是完全相同的实例,但有时可能不同。

所以你想要:

  vl.vega.timeFormatLocale(locale); // show dates in German
  vl.vega.formatLocale(locale); // show numbers with German groupings/ separators