Dynamic thresholds from queried fields

  • What Grafana version and what operating system are you using?
    Grafana v9.3.6

  • What are you trying to achieve?
    I have a table with three columns: value, min and max. These values come from a JSON datasource using the JSON API plugin.

I would like to change the color of the value column on each row based on its compliance (green) or non compliance (red) to the max/min. The issue here though is that the min/max aren’t static, they may vary on different rows.

Note that there are never both min and max on the same row, it’s either there’s a maximum value allowed or a minimum, never both, so I’m not dealing with a range.

I was wondering if there is a workaround to this since dynamic thresholds are not currently possible. I have already tried this solution which isn’t enough in my particular case.

If this isn’t possible in Grafana, I can add another field from my api configuration which determines for each row whether the value is in compliance or not to the targets (for example a yes/no or 1/0 value), but I’m not sure if in that case it will be possible to change the color of the value field based on that as well.

I do not believe dynamic thresholds are possible in grafana.
can you handle this on your api side dynamically and send color value to grafan?


Yes I can add another field on my api side which does the calculation. However what I am trying to achieve is to color the value cell itself, and in that case it would still have to depend on the value of another cell.

1 Like

Hi, any idea which transformation can help me achieve my goal? I have already tried them all and found no workaround unless I am missing something…

That link is direct link to Config from query results transformation.

Could you please further elaborate on how this transformation can be a solution?

Sorry, I gave you only a direction.

Found a solution by using this demo dashboard.

In my JSON API query fields, I created a new field called compliance which is has two possible values green or red based on the values of value and min and max.

The JSONata query looks something like this:

$map(*, function($v, $i, $a) {
  ($v.min != null and $v.value >= $v.min) or 
  ($v.max != null and $v.value <= $v.max) 
  ? 'green'
  : 'red'

Then use the transformation Config from query results following the same logic as the demo dashboard:

Last step:
Add a color background override to the value field: