Bar chart color by threshold

  • What Grafana version and what operating system are you using?
    Grafana Cloud

  • What are you trying to achieve?
    I want to color the bar chart so that values within a threshold are green, and values below or above that range are red.

  • How are you trying to achieve it?
    I have a Trino query that returns a table with 1 row and 2 columns: min and max. I used a ‘config from query results’ to set these as the thresholds. I set the base color to red, the low threshold to green, and the high threshold to red. I set color scheme to ‘from thresholds by value’.

  • What happened?
    All bars are colored red.

  • What did you expect to happen?
    Bars between the low and high threshold should appear green.

I can display the thresholds as dashed lines, so I can tell they are recognized at least.

This person solved it before. :wink:

Oops, that was me! But something is different this time. Maybe because it’s not a time series, I don’t know.

If I just set gradient mode to ‘scheme’ then all the bars disappear.

If I turn off ‘centered zero’ they come back, but still all red.

If I remove the ‘config from query results’ and set the thresholds directly, the colors work as expected, with any gradient mode, with or without centered zero.

Checkout value mapping

That’s interesting, but I need the range to change dynamically based on query results. I see value mapping is an option for that transformation, but I can’t tell how it’s supposed to work. It seems like it would only set a specific value, not a range.

it is a range

your other option is specifying the actual color in your query and using Business Text plugin to use color text or color code such as #0000FF****

you can leverage SQL Expression for that like

1 Like