Akhil
Akhil

Reputation: 373

Unable to change legend name in Grafana using InfluxDB as Datasource and Flux as query language

Unable to change the legend name in Grafana using InfluxDB[flux as query language]. Previously I was using InfluxQL as query language and at that time, grafana provided an option to set the legend name. But after switching to flux, that option seems to be missing. Now it's always showing the legend name as _value, I need to change it to some custom text. Please find below the query I'm using. Thanks for your time in advance.

bucket1 = from(bucket: "NOAA_water_database/autogen")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "ak_api_time" and (r._field == "device_id"))
  
bucket2 = from(bucket: "NOAA_water_database/autogen")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "ak_app_launch" and (r._field == "device_id"))
  
union(tables: [bucket1, bucket2])
 |> filter(fn: (r) => (r.browser == "chrome"))
 |> group(columns: ["device_id"])
  |> unique(column: "_value")
    |> count(column: "_value")

enter image description here

Upvotes: 2

Views: 5460

Answers (2)

Thomas Lemberger
Thomas Lemberger

Reputation: 96

In Grafana, it is possible to add field overrides for the display name (called 'Standard Options > Display Name'). As override value, you can reference values from your query through data links:

Field variables

Field-specific variables are available under __field namespace:

  • __field.name - the name of the field
  • __field.labels.<LABEL> - label’s value to the URL. If your label contains dots, then use __field.labels["<LABEL>"] syntax.

For example, in my InfluxDB-setup, sensor readings have a tag 'item'. I can reference that with $__field.labels.item:

enter image description here

If you want to modify the value of a tag in your time-series, you can do that with the map-function.

Upvotes: 1

Mike Julier
Mike Julier

Reputation: 161

|> set(key: "_wanted_field", value: "Hi, Mom!")

|> set(key: "_unwanted_field", value: "")

Upvotes: 5

Related Questions