Pie chart color scripting

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


vision or perspective?

1 Like


The example is on the propertyChange event of the chart.

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()
		# 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():

	# Set the section colors
	chart.sectionColors = colorList
1 Like

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