Hi Community!
I am using influxdb1.8+ with Grafana 12, I don’t have issues with the query below which perfectly fine.
SELECT COUNT("leak_status_diff")
FROM (
SELECT difference("leak_status") AS "leak_status_diff"
FROM "SensorData"
WHERE $timeFilter
GROUP BY "sensorID", "station"
)
WHERE "leak_status_diff" = 1
GROUP BY "station"
This will give me count number output which is working fine, however on my PIE Chart the legend name is automatically set to something like this:
SensorData.count { station: Pumping Station H }
SensorData.count { station: Pumping Station I }
Which points to my question, is there a way to change the legend name? I know I can do this manually using the Transformations, however the output of my query varies depends on the number of stations, meaning I could have many stations later.
What I want is to simply change the “Legend” name based on my “station”. Which should be
Pumping Station H
Pumping Station I
Any adviced from our community experts will be much appreciated! Thank you very much!
Regards,
using add field override → field with name (select your col name) => display name => now give your legend name to show in panel.
Hi Thanks for the reply.
I actually knew about this, but my requirements is kinda flexible, It means my data could have infinite pumping stations, thus doing the manual override is not possible.
use this organize fields by name transformation and change the legend name according to you…hope it will work for you.
try this
SELECT COUNT("leak_status_diff") as value , "station" as metric
FROM (
SELECT difference("leak_status") AS "leak_status_diff", "sensorID", "station"
FROM "SensorData"
WHERE $timeFilter
GROUP BY "sensorID", "station"
)
WHERE "leak_status_diff" = 1
GROUP BY "station"
2 Likes
Thank you for this, however I tried this one but gives me this error:
mixing aggregate and non-aggregate queries is not supported
Maybe
Select time,difference as value,station as metroc
From (
SELECT COUNT("leak_status_diff")
FROM (
SELECT difference("leak_status") AS "leak_status_diff"
FROM "SensorData"
WHERE $timeFilter
GROUP BY "sensorID", "station"
)
WHERE "leak_status_diff" = 1
GROUP BY "station"
)