I am looking to create a streamlit stacked chart which keeps the order of my dataframe but streamlit is forcing alphabetical order.
Using this code - I want βaβ to always be in the middle but streamlit re-arranges this by always putting βbβ in the middle. What am I missing?
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns=[βcβ, βaβ, βbβ])
st.bar_chart(chart_data)
Hi @Khuthadzo_Masindi, welcome to the Streamlit community!
In this case, itβs not Streamlit itself thatβs forcing anything, as st.bar_chart
is a convenience function around the Altair visualization library (via st.altair_chart
). To directly specify column order, you can switch to using the Altair syntax directly, using order
argument:
https://altair-viz.github.io/gallery/stacked_bar_chart_sorted_segments.html
Best,
Randy