🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Customizing the order of Legends

We are creating a custom visual in Power BI using plotly. Currently, by default, the legends are displayed in certain order and we need to allow the user to specify this legend display order in Power BI. Any inputs on how to write plotly code for this? Thanks in advance.

Legend items are listed in the same order as their corresponding items in gd.data from top to bottom (with the exception of stack bars which are shown in reversed order by default).

You can reverse that order using layout.traceorder: https://plot.ly/javascript/reference/#layout-legend-traceorder

You can also try using legend groups e.g. https://plot.ly/javascript/legend/

Unfortunately, we don’t offer a way to “fully” customize the legend ordering at the moment.

1 Like

The ability to reorder legend items would be really helpful. I see that there’s the categoryorder (and category_orders) for plotly express, however that reorders the actual traces, which breaks my plot. So it doesn’t seem like it’s possible for me to re-order the legend.