How to autozoom graph to data?

Hello everyone, pretty new to Grafana with PostgresSQL and so far I love it! I will be presetting to our company the capabilities of Grafana next week and proposing to switching onto this platform - but I need help with one little thing:

I want to create an environment where I can show processes from industry plant. The dashboard should look something like this at the end (our current application):

So far I got to the point where I can select process numbers based on a query variable.

The problem I am facing right now is that the data shown in the graph doesn’t automatically zoom in to data. This can be a problem because processes can be years old. And the user shouldn’t scroll and “look” for the process through all the years.

Please tell me that there is a way how to do this?
I have been searching on the internet and couldn’t find any answers (I am limited to 2 links so I will put the rest into comments):

  1. Set time range for panel dynamically (autofocus, autozoom)
  2. Auto zoom on available data

Other links about this issue:
3) Time range controls | Grafana Labs
4) [Dashboard time range]: Automatically find time range for data in graphs · Issue #6288 · grafana/grafana · GitHub

I hope I will be proven wrong, but I had a similar question a few weeks back and the answer was that it cannot be done.
You can run the make a panel to user a relative time, which means that it will always fix to the last minutes, hours that you specify:

But it is always a range that ends in the current time. So if your process completes 5pm and you are running the report at 6pm, there will a 1 hour empty space in your graph. Similarly it is always a fixed period to the past. I wanted a graph which zooms in the data on my solar panels, which always start and stop depending when the sun rises and sets in the day. And I could not do it.

I hope you find a solution, it there will be a solution for that in the future. For me it seems what we need is not so much a setting on the graph, but some option to programmatically influence the time range on the dashboard. But in my understanding, this is not possible at the moment. Only if we could add a script to the dashboard page source…


Ah … I can’t believe such a simple yet so powerful feature isn’t added! :frowning:

I hope someone can come up with a solution!

Isn’t it somehow possible for example to connect Y axis to variables?

Actually, have a look at this: GitHub - WilliamVenner/grafana-timepicker-buttons: 📊 Datasource-configured buttons panel plugin which set the time range of your Grafana dashboard

Just spend a few minutes scrolling through it, but it looks like a bespoke panel type where you can have buttons on your panel, and that will change the time range. So your button can determine the start and end of your data range and set the time range to that. Let me know if you can get this working.

I have stumbled across this plugin myself but idk how I could make it do what I want:

I don’t thing adding those buttons will automatically adjust the time range … user still manually has to type in the dates doesn’t he?

Or can I somehow make the buttons default value set up by query?

Yes, you are probably correct. But at least it auto zooms the time range. Maybe there is another plugin somewhere which can press the button for you :slight_smile:

Hmm maybe I could use the code for autozooming and just feed it a value programmatically.

Issue with this is that I can use this only on desktop version and not in cloud am I correct?

Just a bump on this topic. I’m also looking at solar data, but my information comes from Influx (2.6) and the time range is selected by the query (It presents yesterday’s data before 10AM and today’s after 10) and always displays from 6AM - 8PM of whichever day. The query is also set up for overlaying multiple days of data time-shifted to the “current” day.

I’m looking for an unattended option that will just zoom to results from the query; is that not possible?

Editing my thoughts from above slightly-- Looking into RelativeTime and Time Shift I understand that I can do now/d to get to midnight, but I would like a start time of 6AM. If I enter now/d + 6h the + 6h is truncated off.

It doesn’t seem like the selectors are sufficiently robust to do what I am doing in Flux (including if-then statements).

So an auto refresh feature that also does 6 to 8 of today()?

Does it shift left with the clock?

The query does everything I need it to do; the easy solution is to just have the panel display all query results rather than trying to manage zoom from a separate setting.

date = if date.hour(t: now()) >= 10 then today() else experimental.subDuration(d: 24h, from: today())
startoffset = 6h
duration = 14h
start = experimental.addDuration(d: startoffset, to:date)
stop = experimental.addDuration(d: duration, to: start)
startYesterday = experimental.subDuration(d: 24h, from: start)
stopYesterday = experimental.subDuration(d: 24h, from: stop)

(I run two queries, one for “today” and one for “yesterday”, and I timeShift the yesterday data into today so things overlay.)

When the refresh runs, the panel doesn’t shift, as it is already padded out to 8PM today by the yesterday information. [It works as expected when I run it in Influx.]

The problem is that I can’t figure out how to make Grafana “trust” that the time information all needs to be displayed (and nothing else).

1 Like