Vision Chart Component Change Series Line Color Based On Value for Each

Good day,

I am working with the Chart Component in Vision. I am trying to represent open or closed based on value. I have used the door number. If Door5 is 5 then it is closed, if it is 5.5 this is open.

I would like to color each line/series based on if the value, example:

If Door5 most recent value (row0) > 5:
Return Red
Else
Blue

Ideally the chart would all be red and blue. Red if the corresponding door is open vs blue if closed. In the example Door1 is blue and closed, but Door3 would be red.

I tired piggybacking Change colour of item in Chart - #9 by lrose and their solution.

Using this, I’m able to get the first series, but not sure where to go from there.

from java.awt import Color
from org.jfree.chart.renderer.xy import XYLineAndShapeRenderer
from java.awt.geom import Rectangle2D

#grabs a reference to plot of the chart
plot = chart.getPlot()

class MyRenderer(XYLineAndShapeRenderer):	
	def getItemPaint(self,series,row):
		if series == 0 and plot.getDataset(0).getYValue(0, row) > 1: 
			return Color.RED
		elif series == 0: 
			return Color.BLUE

#create an instance of your renderer			
renderer = MyRenderer()

#These lines modify the rendering of the data series
renderer.setSeriesLinesVisible(0,False)

#set the renderer of the plot to your custom renderer
plot.setRenderer(renderer)

Example of Chart with Script.

Example of Dataset:

Example of Chart w/o script:

class MyRenderer(XYLineAndShapeRenderer):	
	def getItemPaint(self,series,row):
		if plot.getDataset(0).getYValue(series, row) > (series + 1):
			return Color.RED
		else:
			return Color.BLUE

Surely?

2 Likes

Yes… Its been a long day. Thank you!

1 Like