Display line_chart for lines that don't use common x data

Hi,

I recently discovered Streamlit and I’m really thrilled about this project as it provides extremely quick data exploration compared to e.g. Dash or Bokeh.

While trying out I came across one question. How could I display data in a line cart that don’t share common x axis data, meaning every line in the chart has their own x,y data pairs instead of sharing the x points and just differ in the y coordinate.

In Dash or Matplotlib I would solve such a issue by adding the lines one after another, however with Streamlit’s line_chart I feel like this is not possible, as all data must be provided when the line_chart is created.

Is this an actual limitation of Streamlit or am I missing some easy workaround?

Hi @Axel_Fiedler, welcome to the Streamlit community!

This isn’t a limitation per se; st.line_chart is a convenience wrapper around st.altair_chart, for times when you want to make a quick chart just to observe your data. Once you have more complex situations, the expectation is that you would use st.altair_chart to customize to your exact needs.

https://docs.streamlit.io/en/stable/api.html?highlight=line_chart#streamlit.line_chart
https://docs.streamlit.io/en/stable/api.html?highlight=line_chart#streamlit.altair_chart

Best,
Randy

Hi Randy,

thanks for your reply! I will look into the functionality of altair_chart.

1 Like