Change background color of vision chart

Sure. I have this in a chart_util library script:

from org.jfree.chart.plot import ValueMarker
from java.awt import Color, BasicStroke
#
# Supply a function to obtain the range value to mark with the given
# color and stroke.
class DynValueMarker(ValueMarker):
	def __init__(self, callable, clr, stroke):
		super(ValueMarker, self).__init__(0.0, clr, stroke)
		self.callable = callable
	def getValue(self):
		return self.callable()

You apply the above in configureChart with a function that reads the desired property. Note that for a classic chart, where this technique is most valuable, you have to put such properties on another component. I usually just use the parent container. This applies upper and lower specification limits to chart, where the props are in the chart's container:

	root = self.parent
	stroke = chart_util.BasicStroke(1.0)
	def getUSL():
		v = root.SelectedUSL
		return v
	def getLSL():
		v = root.SelectedLSL
		return v
	for plot in chart.plot.subplots:
		plot.addRangeMarker(chart_util.DynValueMarker(getUSL, chart_util.Color.RED, stroke))
		plot.addRangeMarker(chart_util.DynValueMarker(getLSL, chart_util.Color.BLUE, stroke))

The classic chart does not call configureChart for every data update the way the EasyChart does, which is why you need something that gets called with chart redraw.

{ If one were picky, and never needed to debug their [expletive], one might not use the intermediate variable v in those callables, or might even supply a lambda.... }

4 Likes