Time range in grafana

Hey i was trying to filter data using time range i am using json api as my data source. What i am trying to do is, in my data source there are columns named discharge, water and date so i want to filter discharge and water using date how can i do that

1 Like

When you define the query that connects to your data source (json API), check the second tab “transform” and then add a kind of transform that acts as a filter and do whatever you need.

Usually, to do filtering operations, you’re better off using an underlying query language if you can (like SQL) to do the filtering before the data gets to grafana, but if it’s a JSON API, sometimes the API won’t let you do that, so you have to do the filtering after the fact in grafana.

Special note - watch out for data types. If your API is returning text strings (which it probably is) you will likely need to first add a transform that turns the text string into a date (another column of data), so that you can filter on a date, and not a string.

Transform docs can be found here

2 Likes

thank you for your answer sir but what i am trying to do use discharge for x-axis and water for y-axis and select the time range on the time selection located on the top of the dashboard is that possible

Please post sample json from your api modifying any sensitive data. like this inline

{
 "discharge": 12,
 "water": 33.3,
"date ": "2023-10-19 12:00:00"

}

Also include long, lat as it seems you want to plot it on geomap

{
“tele_Data_ID”: “3d5f6efe-e52f-4b4e-8031-048e5e776b3a”,
“lS_ID”: “fb2053ce-f1c8-4e8f-8b41-0101bb502e93”,
“date_Of_Measurement”: “2021-11-23T00:00:00”,
“time_Of_Measurement”: “05:09:30”,
“water_Level”: 45.4,
“discharge”: 4560,
“remarks”: “”,
“x_Coordinate”: “”,
“y_Coordinate”: “”,
“device_ID”: “1324090e-794e-2474-311a-0fe2ccd2c320”,
“sediment_PPM”: null,
“sediment_Min_PPM”: null,
“sediment_Max_PPM”: null,
“temperature”: null,
“eConductivity”: null
},
this is what my api returns so i want to put water_Level and discharge on x and y axis and filter the data by date_Of_Measurement

1 Like

Thanks for sharing the API response JSON body.

One suggestion about your API design, before diving into Grafana. I’d be tempted to combine date_Of_Measurement and time_Of_Measurement into a single datetime_Of_Measurement field. That way you’ll be able to filter not only on Date, but also on Time :tada:

Also one more question for you:

  • Which JSON datasource are you using?
    I like to use the Infinity Datasource, as I find it more flexible/powerful.

So picking up where @davidallen5 left off:

I got this working as follows:

  • First, enable the (currently experimental) feature-toggle transformationsVariableSupport. See Configure feature toggles | Grafana documentation

  • Duplicate the time-column, but convert it into a Unix timestamp, using the “Add field from calculation” transform. I happened to use “Reduce row” with “Total” (see screenshot), but other combinations can work here too. Give the field a new name, maybe timestamp

  • Then add another transform “Filter data by values”. This time choose the new field you just named, and then choose Is between and the values $__from and $__to. This will filter your data down to only that which falls inside the range chosen on the dashboard’s time-range picker

1 Like

so it is not for geomap?