Showing relative instead of absolute data in graph

Hi, i’d like to display in a graph the relative data instead of the absolute one. So the graph should always start at zero… anyone has an idea how to solve this?

  1. Relative to what?

  2. Grafana will display whatever data is in your data store (or, whatever data
    comes back from your query), so if you can put relative data (whatever that
    means in your case) into the data store, Grafana will show it.

  3. Depending on what the answer to (1) is, have you considered doing a query
    to return the data in the range you want the graph to cover, and subtracting
    the earliest or latest value in that range, in order to get “relative data”?

It almost certainly depends on what your back-end data store is as to whether
you can do this.

Regards,

Antony.

Hi, thanks for your quick reply. I’ve got the number of accesses of a rest endpoint. When i display it with sum(call_endpoints_total) by (endpoint) i got the sum of all time. Now i want for example the increase of accesses from today, started at zero.

So, how about adding a time constraint to your query?

select sum(call_endpoints_total) where time>now()-24h group by endpoint

should give you the sum over the past 24 hours.

If you go into the Time Range tab of the Grafana query and set Override
Relative Time to “now/d” it should work out the correct query term for your
back-end data store to return just today’s (since midnight) results.

Regards,

Antony.

Yes that works. Is it possible to start at zero?
At the moment i need to substract the values in my head. It would be easier to start at zero…

35

This depends on which back-end data store you are using, and the query
language it supports, as much as anything else.

I suggest you look at the aggregation and summary functions available in
Grafana’s query editor, to see whether any of those does what you need.
Likely looking ones to me are integral, cumulative_sum, or possibly
subtracting first() from the query.

My only experience with Grafana is using Influxdb as the data store, and I
found it very helpful to use the influx command line tool to try out likely-
looking queries before telling Grafana what I wanted, because when Grafana
doesn’t do what I want, it can be difficult to work out “well, what did
happen, then?”, whereas a command-line query will show you all the data which
comes back (or nothing, if that’s the case).

The only other thing I would say in a situation like this is that if you want
relative data to be shown in Grafana, it’s best if you put relative data into
your data store. Even if you later want to turn that into something absolute,
it’s a lot easier to add up all the relative values to get the absolute answer
than it is the other way around.

Regards,

Antony.

Thank you for your help :slight_smile: Then i have to overthink how I store my data.