Is it possible to reuse same piechart query, but with different time span?

Hi all,
This is may first post, and I’m a newbie. But wow, what a nice software this is!

Anyway, I have created a pie chart with about 40 query’s (electricity kWh) of the current hour. Now, I will create one for ‘today so far’, ‘this month so far’ etc etc.

I know I can copy the first chart, and manually change the query time in each query, but is there a better way (one that uses some kind of variable or similar), so I don’t have to change every query every time I want a new time span?

Typically each query looks like this;

SELECT difference(last(“value”)) FROM “Energy_ch6Wh” WHERE $timeFilter GROUP BY time(1h) fill(null)

I am using influx database

Welcome to the forum. What you describe is indeed possible. What happens to your Pie chart when you select Current Hour vs Last 24 Hours? From your query, it appears you are referencing the time picker (WHERE $timeFilter), so your query should be using the dropdown choices in the time picker.

OK, so that probably just shows my newbieness :grinning: I guess I don’t need WHERE $timeFilter then, because I only see the last hour anyways. (Nothing happens when I change the time in the dropdown) - still get the last hour.

In this view, I’m trying to create, I would prefer to have fixed views of all of; current hour and this day/week/month/year etc. So the ‘time interval’ drop-down should not be part of the equation.

You stated “so I don’t have to change every query every time I want a new time span?” There are two approaches: spend time up front to create as many “fixed” pie charts as you want, or create one pie chart that is tied to the time picker. Make sense?

I would try to fix your query so that it DOES reflect the time picker. That’s sort of the point of a time series visualization tool like Grafana. That way your pie chart will dynamically change depending on what time slice you are looking at.

Yes, so I meant that changing all 40 query’s is a rather big job if I want, say, 5-10 pies. But maybe I actually need to do it, I just thought I should check if there’s a smart way than to copy/paste/edit all 200+ rows… :slight_smile:

This is in a kiosk set-up, so once deployed, it should give the data without any input (and there are also other (bar graphs) on the same page that will use the time picker independently of the pies)

OK, got it. I know of no quick way to write the queries for the different pie charts. Just put on some good music and go to work!

1 Like

:grinning_face_with_smiling_eyes:
Thanks for taking your time anyways, now I’m off to select music…