Adding threshold band to Box and Whisker Chart

Hello,

There are following requirement for us with Box and Whisker Chart customization.

  1. To add band/threshold area inside the chart, as yellow and green band in following image.
  2. Currently I dont see options for changing axis font color. As I have a dark background For us default back color can’t be used.
  3. To show mean value inside each box.

Thanks in advance.

Are there any workarounds that i can try using Jfreechart api in configureChart extension functions.

Hi , I have figured this out and here the solution.

All following scripts were added to window custom methods and were called when internalFrameActivated and when from other window events(if needed).


For Changing the Axis Color:

def boxPlox_axis(self, event):
	from org.jfree.chart.ChartPanel import getChart
	from java.awt import Color
	from org.jfree.chart.axis import Axis
	
    JFreechart = getChart(system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart')) #Jfree Get Chart
	boxPlotComponent = system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart') #Boxplot component
	boxPlot = JFreechart.getCategoryPlot() #As Boxplot is a category plot type, Get Category Plot from chart
	axisY = boxPlot.getRangeAxis()#  Get Y Axis of Boxplot ##.getPlotType()#.getCategories()
	axisX = boxPlot.getDomainAxis()#Get X Axis of the Boxplot	
	
    white = Color(255,255,255,255) #Declare Color, White
	axisY.setTickLabelPaint(white) #Set Y Axis tick label
	axisX.setTickLabelPaint(white) #Set X Axis tick label
	axisY.setLabelPaint(white)#Set Y Axis label

For adding threshold / range bands:

def boxPlox_intervalMarker(self, event):
	from org.jfree.chart.ChartPanel import getChart
	from java.awt import Color
	from org.jfree.ui import Layer
	from org.jfree.chart.plot import IntervalMarker
	
	JFreechart = getChart(system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart')) #Jfree Get Chart
	boxPlotComponent = system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart') #Boxplot component
	boxPlot = JFreechart.getCategoryPlot() #As Boxplot is a category plot type, Get Category Plot from chart

	threshold_Hi = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_Hi
	threshold_HiHi = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_HiHi
	threshold_Lo = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_Lo
	threshold_LoLo = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_LoLo
	
	OutsideLimitColor = Color(140, 47, 57,255)
	InsideLimitColor = Color(106, 153, 78,255)
	boxPlot.addRangeMarker(0,IntervalMarker(threshold_LoLo,threshold_HiHi, OutsideLimitColor),Layer.BACKGROUND)
	boxPlot.addRangeMarker(0,IntervalMarker(threshold_Lo,threshold_Hi, InsideLimitColor),Layer.BACKGROUND)

For changing / repainting the box colors based on the threshold / range limits:

def boxPlox_axis(self, event):
	from org.jfree.chart.ChartPanel import getChart
	from java.awt import Color
	from org.jfree.chart.renderer.category import BoxAndWhiskerRenderer
	
	JFreechart = getChart(system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart')) #Jfree Get Chart
	boxPlotComponent = system.gui.getParentWindow(event).getComponentForPath('Root Container.Box and Whisker Chart') #Boxplot component
	boxPlot = JFreechart.getCategoryPlot() #As Boxplot is a category plot type, Get Category Plot from chart
	
	lightBlue = Color(150,205,255,255)
	red = Color(248, 141, 173,255)
	
	threshold_Hi = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_Hi
	threshold_HiHi = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_HiHi
	threshold_Lo = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_Lo
	threshold_LoLo = system.gui.getParentWindow(event).getComponentForPath('Root Container').threshold_LoLo
	
	class MyRenderer(BoxAndWhiskerRenderer):
		def getItemPaint(self,series,row):
			Q1 = boxPlot.getDataset(0).getQ1Value(series, row)
			Q3 = boxPlot.getDataset(0).getQ3Value(series, row)
			if series == 0 and Q1 < threshold_Lo or Q3 > threshold_HiHi: 
				return red
			else: 
				return lightBlue	
	renderer = MyRenderer()
	boxPlot.setRenderer(renderer)

image

2 Likes