# Bar chart Color based on different values

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188>\
**Category:** Ignition\
**Created:** [August 29, 2017, 9:23am UTC](https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188 "2017-08-29T09:23:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IgnitionUserSmy](https://avatars.discourse-cdn.com/v4/letter/i/f475e1/32.png) [@IgnitionUserSmy](https://forum.inductiveautomation.com/u/IgnitionUserSmy)\
**Post date:** [August 29, 2017, 9:23am UTC](https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188/1 "2017-08-29T09:23:36Z")

</div>

Hello everybody,

i am working on a simple bar chart and i would like to color the bars based on several target values.

Following example:

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/aa8b21e0bccf867a9ae97d339a6c327d79e8c579.png)

As you can see i would like to import machine based target values into the barchart, so the formatting can be made by these values. It’s possible for me to provide the target values as a dataset (Machine || target) in Ignition, but i am not shure how to use them in the scripting.

I’m very new into developing Ingition applications, so i hope someone can help me out 🙂

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [August 29, 2017, 9:52am UTC](https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188/2 "2017-08-29T09:52:47Z")

</div>

You can set the colors of the series from a script like this:

```auto
from java.awt import Color
event.source.parent.getComponent('Bar Chart').seriesColors = [Color.decode("#00FFFF"), Color.decode("#FF00FF")]

```

I don’t know how to set the color on individual bars though 😕

But perhaps you can hack your way around by having a “good” and “bad” series in your dataset and using stacked bars. Then you don’t even need dynamic colors, but you do need a script to write data to the “good” or “bad” column depending on the values.

---

<div class="post-metadata">

**Author:** ![IgnitionUserSmy](https://avatars.discourse-cdn.com/v4/letter/i/f475e1/32.png) [@IgnitionUserSmy](https://forum.inductiveautomation.com/u/IgnitionUserSmy)\
**Post date:** [August 29, 2017, 11:34am UTC](https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188/3 "2017-08-29T11:34:09Z")

</div>

@Sanderd17  
Thank you for your help 🙂  
It was possible to solve the problem by using a staked bar chart wird “good/bad” values (in the SQL Statement) for the same measure. Now it is possible for me to show some nice prepared values 🙂

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/92476bc4f048d67fb5a4ded15b88ca894bb7e90b.png)

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [August 29, 2017, 2:46pm UTC](https://forum.inductiveautomation.com/t/bar-chart-color-based-on-different-values/15188/4 "2017-08-29T14:46:17Z")

</div>

On the BarChart component, put the following in the getBarColor extension function.

```auto
	from java.awt import Color

	data = self.data
	categoryName = data.getValueAt(category,"Label")

	red = Color.RED
	green = Color(113,174,70)
	
	if categoryName == "M1":
		if value < 6:
			return red
		else:
			return green
	elif categoryName == "M2":
		if value < 7:
			return red
		else:
			return green
	elif categoryName == "M3":
		if value < 3:
			return red
		else:
			return green
	elif categoryName == "M4":
		if value < 4:
			return red
		else:
			return green
	return defaultColor

```

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c5bf7fab5482fce0e57381878d328377f2c045c1.png)
