Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort order of legends #2640

Closed
linuxbutler opened this issue Sep 1, 2015 · 15 comments
Closed

Sort order of legends #2640

linuxbutler opened this issue Sep 1, 2015 · 15 comments

Comments

@linuxbutler
Copy link

Hi Torkel

I am not sure if I am missing an obvious setting, but I googled around and couldn't find a conclusive answer.

I am using grafana-2.1.0-1.x86_64 and InfluxDB 0.9.3

On all my panels, I am struggling to order the legends in a consistent way. Every time I (re)load the page, the legends appear in a different order. Eg:
image

It would be ideal if I could specify somehow to order by [ none | alphabetically asc | alphabetically desc ]

I think the ideal place to put this would be Edit Panel -> Axis & Grid -> Legend -> Sort Order

However, optionally I would also like to override the sort order. For example, in the image above, I would like to have the order as:
total
dead
disk-sleep
idle
locked
running
sleeping
waiting
zombie

So you can see the order is sorted alphabetically, but I promoted the "total" legend to be first.
For me, it would make sense the add this option to Display Styles -> Series specific option:
image

Something like "sort order override". Then I can put "total" as 1st, and the rest of the series are ordered alphabetically asc or desc.

Hope this makes sense!
Thanks again!

@torkelo
Copy link
Member

torkelo commented Sep 1, 2015

you can specify sort order by clicking on the legend column headers.

Also I would heavily advice against showing avg, min, max on the same legend as these will in many cases be incorrect. For example say your query is select mean(value) ...

That is InfluxDB is going to apply average to get the number of values down to one value per pixel. The legend values are calculated by Grafana client side, so if your query has the mean function then you can show avg in the legend, if you have max then the max legend value will be accurate.

But they cannot be accurate at the same time.

@gnydick
Copy link

gnydick commented Dec 3, 2018

there is no metric name header to click to sort on, seems like a no-brainer of a choice to do it

@stmax82
Copy link

stmax82 commented Feb 17, 2020

@torkelo maybe I'm missing something but I think this should be reopened - if the legend only contains the metric names, there is no column header that can be clicked to sort them...

@Prestaul
Copy link

By editing the json for a panel directly I can add "sort": "current", "sortDesc": false under legend, which sorts both my legend and the stack order of series in my chart. There really needs to be an independent way to sort the stack order and the legend order.

I want to be able to define the stack order based on values (e.g. largest on top) but sort the legend consistently between charts (e.g. sort aliases alphabetically).

@bduffany
Copy link

bduffany commented Dec 7, 2020

Can this be re-opened? Doesn't seem to be fixed

@pumano
Copy link

pumano commented Apr 8, 2021

any news on this?

@muzyka-viacheslav
Copy link

+1
I tried all the proposed workarounds above, and nothing works, unfortunately.
Data sorting is very important, have no idea why it has so little priority in your backlog guys.

@pumano
Copy link

pumano commented Apr 10, 2021

@muzyka-viacheslav I got it via JSON patching as @Prestaul wrote. But looks like it's not hard to add in UI, and I want to add it, via pull request, if I found some spare time.

@muzyka-viacheslav
Copy link

@pumano unfortunately, panel JSON direct changes don't work for me.
Here is the configuration of the legend:
"legend": { "displayMode": "table", "placement": "right", "calcs": [ "sum", "max" ], "sortBy": "sum", "sortDesc": true }

@pumano
Copy link

pumano commented Apr 10, 2021

@muzyka-viacheslav Try to change "sortDesc": true to "sortDesc": false

@parthgajaria
Copy link

Modifying the json works to sort a table view of the legend, but there’s no way to sort the regular legend view by metric either ascending or descending

@pumano
Copy link

pumano commented Apr 11, 2021

@parthgajaria its possible via UI, check settings where you change miltiple value to show or single, then you can choose increasing or decreasing.

@parthgajaria
Copy link

@parthgajaria its possible via UI, check settings where you change miltiple value to show or single, then you can choose increasing or decreasing.

@pumano that isn't for Legend, that's for the hover tooltip

@endlesslycurious
Copy link

To me if the legends don't get sorted consistently then its easy to make the mistake of looking at one chart seeing an interesting metric then looking at the same colour on another chart (graphing different metrics for the same objects) and think your looking at the same object when your not.
image
For example on the CPU chart the interesting blue spike is the prometheus container but the blue line on the next Memory chart is actually a promtail container. If these containers were sorted by name in the legend then I'd expect them to have the same colour on two charts which would make it more intuitive to me when looking for patterns.

@shohei-ihaya
Copy link

By editing the json for a panel directly I can add "sort": "current", "sortDesc": false under legend, which sorts both my legend and the stack order of series in my chart. There really needs to be an independent way to sort the stack order and the legend order.

I cannot sort the order of legends by editing json shown above ( at grafana 10.2.3 )

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests