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:

Solved… I need a nap. Just had to elif

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 == 1 and plot.getDataset(0).getYValue(1, row) > 2:
			return Color.RED
		elif series == 2 and plot.getDataset(0).getYValue(2, row) > 3:
			return Color.RED
		elif series == 3 and plot.getDataset(0).getYValue(3, row) > 4:
			return Color.RED
		elif series == 4 and plot.getDataset(0).getYValue(4, row) > 5:
			return Color.RED
		elif series == 5 and plot.getDataset(0).getYValue(5, row) > 6:
			return Color.RED
		elif series == 6 and plot.getDataset(0).getYValue(6, row) > 7:
			return Color.RED
		elif series == 7 and plot.getDataset(0).getYValue(7, row) > 8:
			return Color.RED
		elif series == 8 and plot.getDataset(0).getYValue(8, row) > 9:
			return Color.RED
		elif series == 9 and plot.getDataset(0).getYValue(9, row) > 10:
			return Color.RED
		elif series == 10 and plot.getDataset(0).getYValue(10, row) > 11:
			return Color.RED
		elif series == 11 and plot.getDataset(0).getYValue(11, row) > 12:
			return Color.RED
		elif series == 12 and plot.getDataset(0).getYValue(12, row) > 13:
			return Color.RED
		elif series == 13 and plot.getDataset(0).getYValue(13, row) > 14:
			return Color.RED
		else:
			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)

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