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
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
vision or perspective?
vision
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()
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
how did i not find this example myself
ignition has got lots of various good examples
Thanks a lot!