Color of Stat panel based on other value/measurement

Hi

Is it possible to display a value on a Stat panel and base the color of it on another value?
More specific:

I would like to display the temperature of two rooms and when the temperature between those two rooms is more then 5°C both stat panels should become red.

All data is stored in a InfluxDB v1.8.
Grafana version is v8.3.3

It is fairly easy to color them based on threshold (from their own value), but not based on a difference between two values, like what I found.

Does someone have a clue?

Thank you!

Kind Regards

Pieter-Jan

What is your datasource?

I’m sorry, is added to the original post.

I assume you are using InfluxQL (not Flux). Very basic approach like this should work:

query A: Room1Temperature
query B: Room2Temperature
query C (use the pencil icon and write the query):
SELECT mean(“Room1Temperature”) - mean(“Room2Temperature”) AS “RoomTemperatureDIFF” FROM “stations” WHERE $timeFilter GROUP BY time($__interval) fill(null)

Thank you for your answer.
Okay, so then I have all values in one panel, but how can I then display the value for Room1Temperature on the panel and color it red when when RoomTemperatureDIFF is greater then 5?

Do the 3 queries, but click the eye icon
image
to disable queries A and B. Query C should still work.

The create the stat panel to display the value in Query C. Change your thresholds and colors as appropriate. The stat panel color should reflect the RoomTemperatureDIFF value and your thresholds. Make sense?

Yes, indeed, make sense, for displaying the value of query C.
But I want display the value of query A (or query B) and use query C for the color of the thresholds.

Is this possible?

Is this issue resolved ? If yes, please explain the solution.

I have something similar requirement. My postgresql db has 2 columns test_time and test_result. This data is collected for every one hour.
I want to display the test_result in the stat panel. Also, if data is not collected for more than one hour, I need to highlight that. That is, value of test_result is displayed as GREEN if difference between current time and test_time less than one hour. And test_result is displayed as RED if the difference between current time and test_time is greater than one hour. Please let me know how to achieve this.

welcome @jpraok

what is your datasource?





Thank you. It is still not working for me. Can you update the threshold to 4 and see whether all three numbers become red ? For me only one number become red

Because i am only apply color to be red only difference field , the same way you can override the value1 and value 2 also. for all the val to be red you can directly set threshold.

I use postgresql database as a source

Does that mean you have condition set for all 3 threshold values ? OR you are setting threshold value for C only ? I am looking for set the threshold for one value (C in your case) and same color should get applied to other values.

please follow the detailed document for some example and you will get the idea so you can build dashboard and solve your problem..

follow the step ,hope it will work for you


use this query

SELECT
test_time,
test_result,
CASE
WHEN NOW() - test_time <= INTERVAL ‘1 hour’ THEN ‘GREEN’
ELSE ‘RED’
END AS color
FROM
test_data
ORDER BY
test_time DESC
LIMIT
1;

and then apply transformation Config query from resule

1 Like

Please post sample data coming back from your query or a screen capture. Are the values for both rooms in one row 2 different columns or 2 rows

It is one row with 2 columns. First column shows “test_time” and 2nd column shows time difference between “now” and “test_time”. If this difference is bigger than x hours, I need to show the first column (test_time) in different colour

This worked !! THANK YOU SO MUCH !!!

1 Like

please mark solution!