I have a query that uses a variable, FWIW like this:
SELECT value from dxdata where analyte='Insulin' and unit='$insulin_units' and time > $kraft_curves-20m and time < $kraft_curves+4h
This returns the correct dataset. However it does nothing to the “view window” or the time range in the panel. This is of course set by the
time selector control.
How do I make the Grafana Panel extend to the time range as specified in the QUERY
Thanks a lot for your help,
Hi @allomorphy - it would be best to flip the approach, and have your query use the time bounds specified by the dashboard’s time picker - see Global variables | Grafana Labs. Would that work for you?
Thank you for your suggestion @svetb
I can understand why you suggest that. The problem here is that we want to relieve the poor time picker (aka the user ) from this chore. You can see why it is so inconvenint to zoom in manually to the several hour long curves that exist randomly over a multi-year period like here:
to find this single curve for example:
What I tried was to populate a variable with all the OGTT values – which act as identifiers of a single curve – and then for the user to select one of these to display a single curve. The QUERY selects the data fine but the $timeFilter or the range or whatever word one uses for the zooming in or out of the panel view itself, has not proved possible for me to change. So it remains a tiny collection of squashed up data points in large empty display.
Would love to find a breakthrough or for someone to say, Forget it.
Thanks again for any ideas and best wishes
Please Join the Health revolution https://blogs.meterbolic.org
Right, I see the issue. So, it is possible to do what you want, but it’ll be kind of hack-y.
Basically, you can create a text panel with some custom JS, which would pick up changes in template variable values, and set the time range appropriately. The latter can be achieved similar to what’s described here: JS within panel to set dashboard refresh interval - #5 by svetb. That thread is about the refresh interval, but the time range is accessible in a similar way (check out the other methods bound to
IIRC, the JS should get reloaded/triggered upon any changes in template variable values - but if that’s not the case, you might have to explicitly bind to that event.
Not sure what your appetite is for implementing something like that, but I feel that it’s probably the best option you have.
Thank you @svetb
Great that there is a way out of this and you are very kind to give a solution.
Would love some helpful eyes on implementing the above suggestion
On the Result url below, you see a months long time window and the ability to select on the Kraft Curves variable different events. What is required is that when a user selects a Kraft Curve on the dropdown, then the user is show the data properly zoomed in on the timeline.
The data QUERY works as may be seen in the link below.
The code in my panel currently combines a text output of a calculated date range set by a template variable
$kraft_curves and attempts to set the zoom to this same time range using the example supplied here:
This was a wild attempt to have the Panel resize in the same way as using the interactive timePicker would resize the view of the Panel to the data.
I am not sure what is the format of
time which need to be defined in
timeService.setTime(newTime) or even if this is the correct approach at all.
Currently I am using nanoseconds like the url uses, and this is almost surely wrong and am not sure what the format of time should be.
Thank you for helping to solve this problem .
The above has been solved by using date time in the format
After some adjustments for scoping, this worked.
Thanks again @svetb for getting this going
The use case for selecting a single variable value works great.
However, the second use case is for a page of panels repeating for each value of the variable.
It seems that the call that worked in the first case is not useful here:
This is because the above sets the time range globally for the entire dashboard and not per panel
Does anyone know what the correct call would be to set the per panel tiem range?
Would be amazing if you could share.
At the bottom fo this thread, they discuss the
Query Options per panel.
I have managed to make these do what I want per panel, but does anyone know how to set this through a call in js, like we call the global
setTime for example.
Look forward to your ideas …