# Bar Chart Colors on Category

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872>\
**Category:** Ignition\
**Created:** [February 26, 2019, 11:46am UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872 "2019-02-26T11:46:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [February 26, 2019, 11:46am UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/1 "2019-02-26T11:46:59Z")

</div>

So i have a simple bar chart based on the first 2 columns, the reason and the minutes. I would like to change the colour depending on the owner of that issue (the 3rd column)

I can change the color based on valve but I want to change it based on the owner. I created a custom dataset on the chart hoping I could define the owner for color but cant get it to work. There will only ever be two owners.

| Weld Cutout | 75 | SS7 |
| --- | --- | --- |
| Coating Repairs | 25 | RAE |
| No Grit | 12 | RAE |
| Roller Issues | 20 | SS7 |
| Weld Issues | 10 | SS7 |
| Re-blast | 70 | RAE |
| Site Issues | 12 | SS7 |
| Clamp Cut | 6 | SS7 |
| Power Cut | 70 | SS7 |
| Reblast | 10 | RAE |
| Weld Reject | 60 | RAE |
| Door Switch | 14 | RAE |
| Scan Issue | 10 | SS7 |

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [March 2, 2019, 11:05am UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/2 "2019-03-02T11:05:48Z")

</div>

Anyone help on this one?

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [March 4, 2019, 5:51pm UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/3 "2019-03-04T17:51:09Z")

</div>

Yes you can use the getBarColor extension function. Here’s an example for the default bar chart

```auto
	from java.awt import Color
		
	if self.data.getValueAt(category, 'Label') == 'Jan':
		return Color.GREEN
	else:
		return Color.BLUE

```

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [March 5, 2019, 5:25am UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/4 "2019-03-05T05:25:12Z")

</div>

Thankyou.

To figure this out in my mind, the bar chart works basically on 2 values. A option like days of the month and a value.

2 variables. How do I add the 3 variable which is what will determine the colors.

On the database table the machine break down reason has a 3rd column called owner. It will either be my company or the client. How do I pull that owner into the bar chart.

I set up a custom property dataset on the bar chart with the 3 columns so i can see the owner when I view the data set, Along with the reason and minutes.

Using your example would I use

> if self.data.getValueAt(category, 'Owner') == 'SS7':  
> return Color.GREEN  
> else:  
> return Color.BLUE

I’m Just confused as ‘owner’ is not an actual value used on the bar chart. Only in the table the data comes from.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [March 5, 2019, 3:33pm UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/5 "2019-03-05T15:33:38Z")

</div>

Are you binding the custom dataset to a SQL query? In that case, you can bind the data property of the chart to only the first 2 columns of the dataset, then use my example to look at the value of the owner column in the custom dataset.

I created a custom dataset called customDS that looks like this:

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

Next, I used an expression binding on the chart data to get the first 2 columns:

```auto
columnRearrange({Root Container.Bar Chart.customDS}, 'reason', 'someNumber')

```

Then, I used the following getBarColor script, which looks at the owner column of the custom dataset:

```auto
	from java.awt import Color
		
	if self.customDS.getValueAt(category, 'owner') == 'SS7':
		return Color.GREEN
	else:
		return Color.RED

```

What I ended up with is this vibrant chart, which I believe is exactly what you are looking for.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/fb8a9b98397f470f3969124aecb8f9e348dbcf1d.png)

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [March 5, 2019, 4:19pm UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/6 "2019-03-05T16:19:41Z")

</div>

That worked a treat, Thank you very very much 😀

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [March 5, 2019, 4:21pm UTC](https://forum.inductiveautomation.com/t/bar-chart-colors-on-category/22872/7 "2019-03-05T16:21:34Z")

</div>

You are very welcome!
