- What Grafana version and what operating system are you using?
Grafana 11.3.1 on Debian Linux 12.8
- What are you trying to achieve?
I have a time series graph with one bar graph and one line graph. The query includes another field that will always be either 1 or 0. I would like the value of that field to determine the colour of the bar graph.
- How are you trying to achieve it?
I’ve looked at overrides and thresholds, but I’ve not been able to use one field to colour another.
Hi,
Have you checked out Config from Query transformation? It might be what you’re looking for.
Thank you. That feels tantalisingly close - I’ve select the bar field as the “apply to” field, and I’ve said the 0/1 field to be “Value mappings / color” but I can’t see how to map the 0/1 to (say) red/green.
Ok, I might have been too quick for that
Unfortunately I’m not quite sure how to do that with just 0/1 values. To use it in overrides it should be a color (e.g. name or hex). A workaround I found is to use Infinity Plugin with CSV mode and listing mapping from your 0/1 value to a color, like in the screen:
Second thing you need to do is to create a variable (in my case query0
) that will return the 0 and 1. The filter expression filters the CSV entries to only interesting color. Here’s my transformation configuration (I think I might have some bug / old data though for Time and vector(1) fields
)
Anyway, if you’re using InfluxDB, you could theoretically return the color instead of 0/1 with conditional logic. AFAIK prometheus doesn’t support such behavior.
1 Like
Thanks for your help. In the end I added a transformation that multiplied the value of the bar graph by my 0/1 field, and representing the result as a bar graph in a different colour. That overlays the original bar graph and so is a good workaround to fix my problem.