Change background color of vision chart

i have created one chart which shows like this:

i want to fill the background color of chart like this:

i want to fill different colors between the lines like o - 15 pink color, 15-25 different color etc. In chart, data is coming continously from the database.

another thing is when the value of LCL,LSL,USL,UCL change, color area will also be fluctuate like as LCL changes 15 to 20 then area of pink color will be change.

I believe you will want to set your plot background to white, and then, simply add some interval markers to your configureChart extension function.


#def configureChart(self, chart):
	from org.jfree.chart.plot import IntervalMarker
	chart.plot.addRangeMarker(IntervalMarker(0, 15, system.gui.color(255, 182, 193, 155)))
	chart.plot.addRangeMarker(IntervalMarker(25, 75, system.gui.color(144, 238, 144, 155)))
	chart.plot.addRangeMarker(IntervalMarker(85, 100, system.gui.color(255, 182, 193, 155)))


1 Like

Oops, didn't see that part. In that case, the answer will be the same, but you will drive the script from your propertyChange event handler and use variables for your range setpoints.

1 Like

It is better to subclass Marker to read the variables on demand when the chart wants to redisplay. This can be done with Axes, too, to compute your own limits from the data when the data changes but configureChart isn't called again.


Thankyou Justin!!

1 Like

Could you show an example of how this is done, for those of us who are ignorant?

1 Like

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.... }


Any idea to do the same with Perspective powerchart ?