Bring Drag & Drop to Dash with Dashboard Engine. ๐Ÿ’ซ Learn how at our next webinar!

Sort stacked bar chart's traces/layers by value


Is it possible to sort the individual column based layers in a stacked bar chart (similar to layout.axis.categoryorder)?

Take this fiddle for example:

I would like to have the data be represented in this way:

(notice that in the case of orangutans and monkeys the LA zoo is at the bottom).

I come from chart.js where in order to get this functionality I had to mess about with creating a custom plugin and was hoping that would have a more elegant solution.


We donโ€™t offer an easy way to do this unfortunately. Traces are stacked according to their place in the input data array.

The easiest workaround I can think of is:

where the two traces are combined into one and we make use of sort transform.

Here is a nice solution in python: