# Dynamically change sorting in stacked bar chart

**URL:** <https://community.plotly.com/t/dynamically-change-sorting-in-stacked-bar-chart/16377>\
**Category:** Dash Python\
**Created:** [December 3, 2018, 1:04pm UTC](https://community.plotly.com/t/dynamically-change-sorting-in-stacked-bar-chart/16377 "2018-12-03T13:04:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nst](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nst](https://community.plotly.com/u/nst)\
**Post date:** [December 3, 2018, 1:04pm UTC](https://community.plotly.com/t/dynamically-change-sorting-in-stacked-bar-chart/16377/1 "2018-12-03T13:04:25Z")

</div>

Hello there,

I am wondering what the best approach is for dynamically changing the order of bars in a stacked bar chart. Right now what I do is before passing any of the traces, I create a “dummy” trace with all the names of my bars as Y, and the X values all as NaN. This dummy trace is ordered in such a way that the bars are sorted with the longest total bar at the top, and then descending from there.  
Here’s a visual:

 ![55](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/d45e8e60fc9953a5c1f7530484836b30e190f879.png)

As you can see, the bars are all ordered by total length of the stacked bar, which is great!  
But I have a very big category “unregistered”, the black bar.  
It is very likely that a user will want to hide specifically that category, and I know this can be done by clicking on it in the legend, but then the chart will look like this:

 ![04](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/b/ba0ae2a32ab80a54caa1c576ac541cf82d3a068d.png)

Now the ordering is all messed up. What I want is for the remaining bars to “reorder” themselves, so I once again go from largest to smallest.

Is there anyway this is possible?
