Auto zoom on available data

I am using Grafana v8.3.2 (afb9e8e5f) on Debian 11 connected to InfluxDB 2.1.1

I want to create a graph, which always shows the solar power generation for the current day. I want the graph to always zoom onto the data available, when the solar inverter turned on, and turned off.

I am using the following flux query to get the data for today by first searching the start and end date when I have data:

starttime = from(bucket: "nodered")
  |> range(start: today())
  |> filter(fn: (r) => r["_measurement"] == "solar")
  |> filter(fn: (r) => r["_field"] == "outputpower")
  |> group()
  |> first()
  |> group(columns: ["_field", "_measurement"], mode:"by")
  |> tableFind(fn: (key) => key._field == "outputpower")
  |> getRecord(idx: 0)

endtime = from(bucket: "nodered")
  |> range(start: today())
  |> filter(fn: (r) => r["_measurement"] == "solar")
  |> filter(fn: (r) => r["_field"] == "outputpower")
  |> group()
  |> last()
  |> group(columns: ["_field", "_measurement"], mode:"by")
  |> tableFind(fn: (key) => key._field == "outputpower")
  |> getRecord(idx: 0)

from(bucket: "nodered")
  |> range(start: starttime._time, stop: endtime._time)
  |> filter(fn: (r) => r["_measurement"] == "solar")
  |> filter(fn: (r) => r["_field"] == "outputpower")

And this is working because if I pick a 7 day period, I only see data for the current day:

But somehow I want to tell this specific panel to zoom onto this data automatically and do not use the time filter of the dashboard.

I understand that I can specify a Relative Time here:

But of course that time will depend on when I view the report. In the morning this could be just a few hours, at the end of the day, it can be up to 10 hours.

So essentially I need an option for the graph to automatically zoom onto the available data. I don’t see any such options in the graph properties.

hi @nygma2004 :wave:

as you noted, i don’t think such an option exists. the best solution i can think of is to use the Today so far option in the timepicker:

image

this basically matches your flux query as well.

edit: if you want this to only apply to this specific panel, you can specify now/d in the Relative time query options:

Hi @ashleyharrison, thank you for your response. now/d is not bad, probably I am better off manually zooming onto the available data.
I was thinking if it would be possible to use some browser side script to read the start and end date from a query and use that to default a time range. But as far as I can see, no such scripting is allowed in Grafana.

1 Like

Did you found a way how to autozoom?

No, I did not. But did not spend the time either to look into those we talked about in your thread.