[Solved] Organizing the order of items in a pie chart legend

Greetings,

I am trying to to make the legend of a pie chart display in a set order, rather than in descending order.
I have checked other topics on this subject but all of them seem to have been abandoned without an answer being found.

I am aware of the operator legend_traceorder that is supposed to be used for this purpose.
However, specifying “traceorder: normal” leads to my data still being displayed in descending order.

It is my understanding that I could group my legend to achieve the desired effect, albeit in a roundabout fashion, but it seems that grouping a legend is only possible with other types of charts, not pie charts. Is there in fact some way to accomplish this with a pie chart?

Below is the code for a pie chart I copied from the reference site to use as an example.
I would want to have the legend display in the order “Residential, Non-residential, Utility”.

Thank you in advance for your assistance.
Any new information, or even confirmation that this is not possible, would be appreciated.

var data = [{
  values: [19, 26, 55],
  labels: ['Residential', 'Non-Residential', 'Utility'],
  type: 'pie'
}];

var layout = {
  height: 400,
  width: 500
};

Plotly.newPlot('myDiv', data, layout);
1 Like

I think you’re looking for sort: false

1 Like

Thank you! Specifying this parameter has solved my issue!

I did not think to look in the parameters for the data regarding the settings for the
legend, it seems like the posters of numerous other topics on this subject had the same issue.

I would really appreciate it if you or anyone with the ability to edit the reference could note that this parameter affects the legend, or add a note regarding it to the section on legends.

Thanks again!