Hi everyone,
My problem is pretty straightforward.
I have a variable with 2 values: val1, val2.
If val1 is chosen, I want my chart colors to be green-yellow.
If val2 is chosen, I want my chart colors to be blue-red.
I have not found a way to bind chart colors to a variable.
Thanks in advance for your help!
Here’s a possible solution. It’s sort of a hack, but it might work for your use case:
- Create a custom variable with the labels “val1” and “val2”.
Note that val1 : ⠀, val2 : ⠀⠀
is a list of two key : value pairs, where the value for “val1” is Unicode character U+2800 (blank space), and the value for “val2” is just two U+2800 characters. This is just so they’ll be “invisible” in your legend, but Grafana will not treat them as whitespaces.
-
Change the alias for your data sources so they’ll include the variable, something like “series1$query1” and “series2$query1”.
-
Create an override for each series and each variable value. Give each specific combination the specific color that you want:
Note that the values in the “Fields with name matching regex” inputs contain the invisible characters.
This gets you the following, where the colors of the 2 series change from green-yellow to blue-red, depending on the selection of the query1 variable: