How to set item color based on item label in bar chart?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
cmaynes
Posts: 2
Joined: Mon Dec 04, 2017 8:20 pm
antibot: No, of course not.

How to set item color based on item label in bar chart?

Post by cmaynes » Thu Jun 28, 2018 11:57 am

I am using the latest version of Jython.

I have a barchart where I have one series and need to assign different colors to the items based on the item labels. I have looked everywhere and I cannot find a solution.

The data looks like this:

Grouping Count GroupName
VSWR_4M 960 CONNECTOR
PIM_4M 62 CONNECTOR
VSWR_DM 74 FLEXTYPE
VSWR_4R 99 LENGTHLABEL

I currently has the following subclass:

class CustomRenderer(BarRenderer):
def getItemPaint(self,row,column):
ds = self.getPlot().getDataset()
val = ds.getValue(row,column)
if val == 'CONNECTOR':
return Color(50,50,50)
if ds.getValue('GroupName',column) == 'CONNECTOR':
return Color(10,0,255)
elif ds.getValue('GroupName',column) == 'FLEXTYPE':
return Color(10,100,255)
elif ds.getValue('GroupName',column) == 'LENGTHLABEL':
return Color(10,200,255)
else:
return Color(200,200,100)

Post Reply