Eoin
Eoin

Reputation: 21

Grafana panel values not sorting consistently with InfluxDB

What Grafana version and what operating system are you using? 10.4 Using Flux Query Language

What are you trying to achieve? Using the Stat panel (in a repeating row by variable ${vocDeviceName}, I wanted to change the order in which the data is displayed from the Grafana default order.

How are you trying to achieve it? Using this query:

from(bucket: "data")
  |> range(start: -21d)
  |> filter(fn: (r) => r._measurement == "co2SensorData" and r.co2DeviceName == "${co2DeviceName}")
  |> filter(fn: (r) => r._field == "temperature" or r._field == "humidity" or r._field == "light" or r._field == "co2" or r._field == "voc" or r._field == "vdd" or r._field == "motion")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({
      _time: r._time,
      co2DeviceName: r.co2DeviceName,
      temperature: r.temperature,
      humidity: r.humidity,
      light: r.light,
      co2: r.co2,
      voc: r.voc,
      vdd: r.vdd,
      motion: r.motion
    })
  )
  |> yield(name: "results")

What happened? Upon trying multiple other types of queries including this one, each time the page is refreshed and a repeating panel is rendered, the order is completely different each time.

What did you expect to happen? I expected the data in the panels to return the mapped sorted order from the query.

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

Screenshot to help visualize Default Grafana Order: [Default Grafana Order](https://i.sstatic.net/nuDbc0xP.png)

Custom Order Query: [Custom Order Query](https://i.sstatic.net/2ibgsPM6.png)

Upvotes: 2

Views: 80

Answers (1)

Jan Garaj
Jan Garaj

Reputation: 28696

Use transformation Organize fields by name.

Public stat panel example with ordered fields (coupled frontend/backend):

enter image description here

Of course I don't have exactly your data, so you may need some additional transformation(s) to achieve desired order.

Upvotes: 1

Related Questions