Bar Chart Colors on Category

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

Anyone help on this one?

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

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

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.

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

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

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:

	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

2 Likes

That worked a treat, Thank you very very much :grinning:

You are very welcome!