# Vision Bar Chart Component - Dynamic bar color

**URL:** <https://forum.inductiveautomation.com/t/vision-bar-chart-component-dynamic-bar-color/93461>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [July 19, 2024, 1:14pm UTC](https://forum.inductiveautomation.com/t/vision-bar-chart-component-dynamic-bar-color/93461 "2024-07-19T13:14:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Graber](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Matthew\_Graber](https://forum.inductiveautomation.com/u/Matthew_Graber)\
**Post date:** [July 19, 2024, 1:14pm UTC](https://forum.inductiveautomation.com/t/vision-bar-chart-component-dynamic-bar-color/93461/1 "2024-07-19T13:14:05Z")

</div>

Hi everyone,

I have this bar chart (pictured below) that is returning 2 series of data from a dynamic date range. I am wanting to change the bar color of the first series based on if the value is higher or lower than the second series. I imagine there is a way I can do this in the getBarColor function (green if greater than, red if less than), I just don't know how. Can anyone help me out with this?

 ![Bar Chart](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/afbbf36ba2c1b4476236590eb8e0014a32d7f167.jpeg)

Also, here is my sql query for this chart if that's helpful:

 ![SQL query](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64d5d0de8490e31d6f23ec4b915692ce35f7a645.jpeg)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 20, 2024, 3:24am UTC](https://forum.inductiveautomation.com/t/vision-bar-chart-component-dynamic-bar-color/93461/2 "2024-07-20T03:24:04Z")

</div>

> [@Matthew\_Graber](#):
>
> I imagine there is a way I can do this in the getBarColor function

Correct. Simply check the next column for the current row in the chart's dataset to the current value anytime series one is being evaluated by the extension function.

**Example:**

```python
#def getBarColor(self, [...] defaultColor):
	# This script assumes that the "Exact Order" parameter is set to "By Row"
	
	# Define the necessary colors
	seriesOneHighValueColor = system.gui.color('lightgreen')

	# These two variables can be explicitly defined in the script,
	# ...or the extension function's defaultColor variable can be used to simply return the default color for each series 
	seriesOneDefaultColor = system.gui.color('lightblue')
	seriesTwoDefaultColor = system.gui.color('darkgrey')
	
	# chart data zero indexed columns = [Label, Series 1, Series 2]
	# The series variable in the extension function is zero indexed,
	# ...so series == 0 will be Series 1 and series == 1 will be Series 2
	# The category variable represents a row index in the chart's dataset 
	
	# If Series 1 is being evaluated,
	# ...and its row value is greater than the series 2 value on the same row of data,
	# ...apply a special color. Otherwise, use the default colors for the respective series
	if series == 0 and value > self.data.getValueAt(category, 2):
		return seriesOneHighValueColor
	elif series == 0:
		return seriesOneDefaultColor # or simply defaultColor
	else:
		return seriesTwoDefaultColor # or simply defaultColor

```

**Result:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/2980ca9e8b2cd9f81e3e4e614620239612eac379.png)

---

<div class="post-metadata">

**Author:** ![Matthew\_Graber](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Matthew\_Graber](https://forum.inductiveautomation.com/u/Matthew_Graber)\
**Post date:** [July 22, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/vision-bar-chart-component-dynamic-bar-color/93461/3 "2024-07-22T19:37:00Z")

</div>

That did it! Thank you
