Naming graphs using flux2

Hey all!

I am all new to grafana and flux. I’ve set up my homeassistant to log data into influxdb and have set up a few graphs. While it’s certainly more difficult to find examples for flux than for sql I’ve gotten most of my stuff set up and and I’m just going with the learning curve.

One thing I have so far failed to find anything about - probably due to a lack of knowledge about which terms to use - is the name of graphs. For instance, if I have 3 graphs on one chart for different temperatures in my rooms, the naming of the graphs is like temperature {domain="sensor", entity_id="livingroomsensor_temperature"}
I would really like this to be just Livingroom Temperature or whatever custom string I’d like to choose :slight_smile: I am quite certain this is a very simple task but I struggle to find a simple answer.
Below is my query:

from(bucket: "home")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["domain"] == "sensor")
  |> filter(fn: (r) => r["entity_id"] == "livingroomsensor_temperature")
  |> filter(fn: (r) => r["_field"] == "temperature")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

thank you!

Did you find a solution for this? I’m also trying to work out how to name different data captures on a single graph (legend labels).

no i did not. I am also surprised that there was not a single reply. I’d actually think that this was a common task to do, also surprised how little activity there is in this forum …

Did you try the “Display name” field override?

Oh, no I have not. Unfortunately having no experience with neither grafana nor flux I find this documentation very uncomprehensible. How would I implement this in the above example? I’m sure once I see it it’s very obvious …

Hard to explain without creating a series of screenshots, but basically (assuming you’re on Grafana 7.x):

  1. Open the panel editor and click on the “Overrides” tab on the right
  2. Click the “Add an override for” button; select “Field with name”. In the drop-down select the current name of your field (as yielded by the query)
  3. Click “Add an override property” and select “Display name”
  4. Enter the name you would like to see

There is actually another (maybe preferable) way to do this inside the query itself - which also works for Grafana 6.x. See discussion here, which is basically a discussion of the issue you’re having. This approach involves adding a line like

|> map(fn: (r) => ({_value: r._value, _time: r._time, _field: "My Temperature"}))

before the yield() line, with the name you want. Check the discussion I linked to if you need to do this dynamically for multiple series.

1 Like

Both ways work great! Thank you very much! A real pity the process to getting here was surprisingly counter intuitive. But makes me even happier I finally got this sorted :rocket:
thank you!

1 Like