Is it possible to set the locale for Altair charts in Streamlit?

I display charts in Streamlit with Altair.
Altair uses d3-formatting to set the format of labels.
The default locale for d3-formatting is en-US, which predictably renders $ as the currency symbol. For my work, I need to render € as the currency symbol though.

This has been brought up on StackOverflow in the context of working with Jupyter Notebook before.

Jake, one of the maintainers of Altair, replied to the question:

It’s possible, but unfortunately not well supported. formatLocale() is a javascript function that must be called by the renderer. The Javascript code used by Jupyter Notebook and JupyterLab is hard-coded within their respective vega extensions, so there is no way to change this for Altair charts visualized in those frontends.

If you want to adjust the locale yourself, the easiest way would be to export the chart to HTML ( chart.save('mychart.html') ) then add a call to formatLocale in the javascript within the HTML output.

If you want to do this in a more automatic/repeatable, you could modify Altair’s html output template (source) and create your own exporter function that converts a chart to HTML with locale settings or other custom javascript.

Is it possible to set the locale for Altair charts in Streamlit?

1 Like

Hi @jan-scorl,
thanks for your question, I don’t think at this moment there is first class support for locale in Streamlit. I wonder we can add custom support by calling formatLocale on the javascript side. Let me file a FR for this.

Matteo