Setting colors dynamically for stacked bar chart

Hi, I am using Grafana 8.1.7. I am trying to build a stacked bar chart like this:

The table view for it looks like this:
Bento_Test_3 | Bento | Bento_Test_2 | Bento_Test | device state
4 | 1| 8| 3| Offline
| | | 2| Online

I am looking for a way to set different color for each numeric column dynamically, because I don’t know in advance how many numeric columns there are and what their names are, as they are dynamically generated by a complex sql query.

The description of “Classic palette” option provided in the documentation looks quite suitable:
“Grafana will assign color by looking up a color in a palette by series index”.

But when I try to apply it, it sets different colors only in the legend but all the bars get colored the same way and I don’t get why:

Any idea why it happens? Or perhaps there is another solution for it?

Thank you!

welcome to the :grafana: forum, @anastasiatepper

Have you explored using value mapping for this? It handles these visualization issues well:

Hey @mattabrams, thank you for your reply!

But in my case the colors do not depend on the values. Just each numeric column should have its own color. So all values from specific numeric column should have the same color.

E.g. you can see there are the blue sections in both bars for the column “Bento_Test” - they should be the same color regardless of their values.

this might still be possible using field overrides and setting a color for every field (column)

Can you please clarify what you mean by “setting a color for every field (column)” in context of doing it dynamically?
If I knew how many columns there are and what their names are I would do it using “Single color” and “Field with name”, but the point is that it’s unknown in advance

1 Like