changing the locale for vega lite

How can I change the locale for vega lite?
(I would like to have the labels for the time axes based on German locale):

Any help would be greatly appreciated!

hi @EE2dev,

i never used vega, but it looks to me like you need vega-embed for that. I have send you a suggestion. Also this notebook might help:

viel spaĂź :slight_smile:

2 Likes

Thanks a lot! That’s what I suspected but it was not clear to me from the documentation.
That means I have to switch to vega to be able to set the locale?

I updated my example adding two lines which @tau showed:
embed = require("vega-embed@4")
as a new cell
and
embed.vega.timeFormatLocale(locale);
Thanks a lot!

The solution posted by @EE2dev seems to work, but only partially. When using timeUnit('yearmonth'), formatting reverts to en-US locale. See example here:

@esparanc: Your example seems to work fine. I think you observed the same effect I did: on one or two days May3rd/4th this vega localization didnt work (also my example was shown in en-US locale. I don’t know what the reason was - maybe the npm packed vega-embed or vega-lite was updated on npm and had that bug for 2 days …?!

[update 07/17/2020]: Thanks to @visnup this question got the correct answer - see also this stackoverflow question: https://stackoverflow.com/questions/62637131/how-to-set-time-axes-labels-ticks-based-on-german-locale/62957447#62957447

There is no need to use embed.vega… Quite the opposite, it might not be loaded in the correct order.

Thus the solution is as simple as adding this line:
vl.vega.timeFormatLocale(locale);

1 Like