Hi,
Using Grafana v9.2.5, reposting this since my first post got auto-deleted by the spam filter
I’m trying to graph values deviating from zero using the gradient colouring in Grafana.
I can’t get this to work how I want. I have values ranging from ± x (say, 2% either side of zero) and I want to colour them based on their distance away from zero.
Essentially I want a gradient of [red, yellow, green, yellow, red], mapped to [-2%, -1%, 0%, +1%, +2%].
The in-built gradients don’t seem to support this, they are only one-way. If I try mapping my values to the red-yellow-green gradient, it maps negatives as green, around 0 as yellow, and positives as red:
I can get the colour mapping working correctly if I also include a helper column in my SQL that grabs the absolute value, and use the “Color by field” setting in grafana to colour the non-ABS data with this scale. That way I can colour it according to the ABS(), giving green around 0 and red as it deviates away from 0 in either direction.
The problem with this is that in order for the colour scale to work this way, I need to set graph min as 0, and max as +2. This prevents me from viewing the entire negative side of the plot.
If I map the ABS(val) to the green-yellow-red gradient and change the minimum to -2, then I can see the numbers correctly but the gradient is incorrect:
This is because green-yellow-red is mapped to the full range of [-2, +2] and I’m only colouring according to the ABS which is between 0 and +2.
The only way I can get this to work is by using the symlog scaling mode, setting the linear region to my full data range, and setting the min/max to [0 to 2]. Somehow in this mode, it will still show both sides of the graph regardless of my min/max settings, and then the gradient will map correctly:
With these settings there are new problems:
- The axis bugs out - it only shows the center-point and no other points or gridlines, even if I force them on.
- I can’t control the maximum values in the plot. If I want to show +10 to -10, I have no way of doing that. Even if I change the max to +10, the gradient will successfully map to this new range but the above value of 1.5% will still be the same size, it doesn’t scale back. It seems stuck on some sort of auto-scaling.
- This seems wrong to be using symlog scaling as a hack to get the gradient colouring to work.
Is there any way to do this correctly with linear scaling mode, gridlines, and adjustable graph axes min/max?
Thanks