Unable to sort the Legend in a dashboard query

  • What Grafana version and what operating system are you using?

  • Grafana v11.1.3 Windows 10

  • What are you trying to achieve?
    Im Trying to sort the Legend of my newly create Dashboard

  • How are you trying to achieve it?
    I tried searching for possible edits to my query and tried several data transforms

  • What happened?
    What do you mean what happened it didnt work

  • What did you expect to happen?

  • i expected it to work

  • Can you copy/paste the configuration(s) that you are having problems with?

  • This is my query so far: ifHighSpeed{instance=“192.168.8.250”} unless (ifIndex>=1000000 or ifIndex==1057) i didnt find any option to resort the IfName to match the order i need.

  • It sorts it like this 1:1,1:10,1:11 i want it to sort it like this 1:1,1:2,1:3,1:4…

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • No Logs or errors

  • Did you follow any online instructions? If so, what is the URL?

  • Same Problem as this topic:

  • Unable to sort table legend on name or values

Those are string values, so grafana is sorting them correctly. to sort it properly you will need to convert those values to maybe numeric

see this examlpe using ms sql

;with src
as
(
	--1:1,1:2,1:3,1:4
	select '1:1' as zoo union
	select '1:10' union
	select '1:11' union
	select '1:2' union
	select '1:3' union
	select '1:4'
)
select zoo , 
   cast(replace(zoo, ':','.') as decimal(10,2)) as zaa
  From src 
 order by 2
 --order by 1 --1:1, 1:10, 1:11, 1:2, 1:3, 1:4
 --order by 2 --1.10, 1.10, 1.11, 1.20, 1.30, 1.40

i forgot to add i am using Prometheus/PromQL. is it possible to order by in PromQL? I tried using sort and tried sort_by_label but if i use sort_by_label i get the error
Error executing query: invalid parameter “query”: 1:1: parse error: function “sort_by_label” is not enabled

How do i convert them into Numeric in Prometheus or Grafana?

im using prometheus/snmp_exporter as a data source.
How do i convert those into Numeric Values on Grafana/snmp_exporter?

Are those values always 1:< number >? Or can it be < number >:< number >?

If the first, you can strip the 1: using (I think) grafana transformation, then convert it to number and sort by that. If that doesn’t work (or the second scenario) then, deep breath

You can use prometheus function label_replace to split those “numbers” into two different labels (considering there are alwyas two):

label_replace(label_replace(your query, "major", "$1", "your current label", "(.*):(.*)"), "minor", "$2", "(.*):(.*)") 

after that your query should have two more labels (major i minor), then in grafana transformations you convert the type to number (possibly using some kind of sort transformation after). I’m not sure it’ll work out of the box though.