Is there any way to change the order of Grafana panel stacked series that come from the same PromQL query?

Is there any way to change the order of Grafana panel stacked series that come from the same PromQL query?

This is very easy when there are multiple queries (just drag and drop up or down), but I don’t know how to do it when all those series come from the same query.

Example:

If I do this 3 queries separately I can order of panel series:

s3_fetchs_durations_bucket{le="0.001"}
s3_fetchs_durations_bucket{le="0.01"} 
s3_fetchs_durations_bucket{le="0.1"}

If I do this this single query I get all the same results but no control of series order:

s3_fetchs_durations_bucket

welcome to the :grafana: community @francardoso93!

I was curious about your question and found this old github issue that says the stacks sort in the same order as the legend: https://github.com/grafana/grafana/issues/9789

I tested it out and it seems to hold true even though it’s not documented, give it a try and let me know if it works for you too!

The options to change in the bar chart to get the stacks sorted are:

I tested with the stacked bar chart here on play.grafana.com and saw the bars change order depending on the legend sort