# Pie chart color scripting

**URL:** <https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451>\
**Category:** Ignition\
**Created:** [July 2, 2021, 10:50am UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451 "2021-07-02T10:50:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 2, 2021, 10:50am UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451/1 "2021-07-02T10:50:24Z")

</div>

hi  
I need to assign pie chart colours based on the dataset column names. I had i look into documentation but still don’t know ☹  
Any chance you advise me in the right direction please?

Regards

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 2, 2021, 10:56am UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451/2 "2021-07-02T10:56:14Z")

</div>

vision or perspective?

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 2, 2021, 1:15pm UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451/3 "2021-07-02T13:15:36Z")

</div>

vision

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 2, 2021, 2:07pm UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451/4 "2021-07-02T14:07:15Z")

</div>

The example is on the propertyChange event of the chart.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/e/9ee3c32a30f60f6529ffe83c8f037582fdfffb6a.png)

```python
if event.propertyName == 'data':
	''' 
	    Assign colors to known labels in a pie chart 
	    Otherwise, assign a default color
	'''
	from java.awt import Color
	
	colorDict = {'Apples' : Color(200,0,0),
				 'Bananas' : Color.YELLOW,
				 'Kiwis' : Color(142, 229, 63),
				 'Oranges' : Color.ORANGE,
				 'Grapefruit' : Color(253, 89, 86)
				}
	
	chart = event.source
	
	# Get label names
	if chart.extractOrder:
		# Extract by Row
		labelList = chart.data.getColumnNames()
	else:
		# Extract by Column
		labelList = chart.data.getColumnAsList(0)
	
	colorList = []
	
	# Check if a label is in the dictionary. 
	# Use the assigned color if found, otherwise use dark gray
	for label in labelList:
		if label in colorDict.keys():
			colorList.append(colorDict[label])
		else:
			colorList.append(Color.DARK_GRAY)

	# Set the section colors
	chart.sectionColors = colorList

```

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 2, 2021, 3:27pm UTC](https://forum.inductiveautomation.com/t/pie-chart-color-scripting/48451/5 "2021-07-02T15:27:57Z")

</div>

how did i not find this example myself 🙂  
ignition has got lots of various good examples  
Thanks a lot!
