Black Lives Matter. Please consider donating to Black Girls Code today.

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 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:

You can also try using legend groups e.g.

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