Flux Variable For "From" and "To" in Date Picker

Hello -

I have a dash that displays slices of data across various time ranges. When the user selects variable drop down for a specific slice, the data presented is outside of the current viewing window, and they need to click ‘zoom to data’ to see the newly selected slice.

I’ve created a variable that can define human readable or epoch timestamps based on the slice selection, however I’d like to know if there’s a way to feed that into the date picker ‘from’ and ‘to’ selectors?

Welcome @ajohnson512 to the Grafana forum.

Can you share your Flux query? My guess is that you’ll need to do something like this:

// Convert the Grafana variable to a time value
timeVariable = time(v: "${timeVariable}")
// Dynamically set query range based on Grafana variable
startTime = date.add(d: -1s, to: timeVariable)
stopTime = date.add(d: 1s, to: timeVariable)

from(bucket: "your_bucket")
    |> range(start: startTime, stop: stopTime)