# Streamlit stacked chart forcing alphabetical order

**URL:** <https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668>\
**Category:** Using Streamlit\
**Tags:** pandas\
**Created:** [June 4, 2021, 5:21pm UTC](https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668 "2021-06-04T17:21:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khuthadzo\_Masindi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/khuthadzo_masindi/32/6466_2.png) [@Khuthadzo\_Masindi](https://discuss.streamlit.io/u/Khuthadzo_Masindi)\
**Post date:** [June 4, 2021, 5:21pm UTC](https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668/1 "2021-06-04T17:21:02Z")

</div>

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)

 ![image](https://global.discourse-cdn.com/streamlit/original/2X/e/ee7f1fd564f1ab3829437e05d887c22bbdffa06a.png)

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [June 7, 2021, 3:05pm UTC](https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668/2 "2021-06-07T15:05:44Z")

</div>

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](https://altair-viz.github.io/) 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](https://altair-viz.github.io/gallery/stacked_bar_chart_sorted_segments.html)

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![Khuthadzo\_Masindi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/khuthadzo_masindi/32/6466_2.png) [@Khuthadzo\_Masindi](https://discuss.streamlit.io/u/Khuthadzo_Masindi)\
**Post date:** [June 16, 2021, 1:38pm UTC](https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668/3 "2021-06-16T13:38:22Z")

</div>

That works. Thank you!

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [August 15, 2022, 8:34pm UTC](https://discuss.streamlit.io/t/streamlit-stacked-chart-forcing-alphabetical-order/13668/4 "2022-08-15T20:34:24Z")

</div>


