# Change single color by variable

**URL:** <https://community.grafana.com/t/change-single-color-by-variable/126338>\
**Category:** Grafana\
**Tags:** dashboard-variables, visulazation, templating, bar-chart, color\
**Created:** [July 16, 2024, 12:57pm UTC](https://community.grafana.com/t/change-single-color-by-variable/126338 "2024-07-16T12:57:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedchenkovmihail](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@fedchenkovmihail](https://community.grafana.com/u/fedchenkovmihail)\
**Post date:** [July 16, 2024, 12:57pm UTC](https://community.grafana.com/t/change-single-color-by-variable/126338/1 "2024-07-16T12:57:53Z")

</div>

Hi everybody. A little digression.

I created a variable in the variables tab and named it my\_color, it is a custom type with a value of 24c38e. I want to use this variable as ${my\_color} in visualizations, for example, “bar chart”. But there I only see a selection of pre-set colors or a selection on the palette, I can’t insert a variable like ${my\_color} and there’s no place for it.

Is it even possible to change the color using variables?

The idea is that the color can be changed to any color quickly

Example, it was

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/3/4344d913e16b1f3accb15de5404db7b0cbf250b4.png)

became

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/0/4/0451428182378df88146e4cf82a79a60472f4457.png)

Thanks for any advice

---

<div class="post-metadata">

**Author:** ![ebabeshko](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@ebabeshko](https://community.grafana.com/u/ebabeshko)\
**Post date:** [July 16, 2024, 2:13pm UTC](https://community.grafana.com/t/change-single-color-by-variable/126338/2 "2024-07-16T14:13:21Z")

</div>

Hello, check if this helps:

> [@How to get a dynamic threshold in stat panel?](https://community.grafana.com/t/how-to-get-a-dynamic-threshold-in-stat-panel/111105/12):
>
> May be ‘Config from query results’ transformation would help in your case: [https://play.grafana.org/d/Fc6gwV4nz/transforms-config-from-query?orgId=1&viewPanel=6](https://play.grafana.org/d/Fc6gwV4nz/transforms-config-from-query?orgId=1&viewPanel=6) Add additional field to your query that would contain required value color basing on calculated in the same query dynamic threshold.

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [July 16, 2024, 2:53pm UTC](https://community.grafana.com/t/change-single-color-by-variable/126338/3 "2024-07-16T14:53:11Z")

</div>

as far as I know you cant change colors based on variable in the stock bar chart but you can if you use Business Chart plugin

docu: [Business Charts | Volkov Labs](https://volkovlabs.io/plugins/volkovlabs-echarts-panel/)

> **[Examples - Apache ECharts](https://echarts.apache.org/examples/en/editor.html?c=bar-data-color)**
>
> Apache ECharts, a powerful, interactive charting and visualization library for browser

implementation in grafana  
 ![chrome-capture-2024-7-16](https://us1.discourse-cdn.com/grafana/original/3X/b/5/b56bd604b05e593d6245357a6f694873f83dce94.gif)

---

<div class="post-metadata">

**Author:** ![ebabeshko](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@ebabeshko](https://community.grafana.com/u/ebabeshko)\
**Post date:** [July 16, 2024, 3:20pm UTC](https://community.grafana.com/t/change-single-color-by-variable/126338/4 "2024-07-16T15:20:19Z")

</div>

> [@yosiasz](#):
>
> as far as I know you cant change colors based on variable in the stock bar chart but you can if you use Business Chart plugin

With transformation [mentioned above](https://community.grafana.com/t/change-single-color-by-variable/126338/2) that is achievable with stock bar gauge:

![bar gauge](https://us1.discourse-cdn.com/grafana/original/3X/0/0/0082e812624cef4fa046eff58a8f9abd2c879846.gif)

---

<div class="post-metadata">

**Author:** ![fedchenkovmihail](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@fedchenkovmihail](https://community.grafana.com/u/fedchenkovmihail)\
**Post date:** [July 17, 2024, 6:27am UTC](https://community.grafana.com/t/change-single-color-by-variable/126338/5 "2024-07-17T06:27:10Z")

</div>

Thank you all for the answers. I used @ebabeshko solution
