# Adding threshold band to Box and Whisker Chart

**URL:** <https://forum.inductiveautomation.com/t/adding-threshold-band-to-box-and-whisker-chart/40394>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [November 6, 2020, 2:53pm UTC](https://forum.inductiveautomation.com/t/adding-threshold-band-to-box-and-whisker-chart/40394 "2020-11-06T14:53:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [November 6, 2020, 2:53pm UTC](https://forum.inductiveautomation.com/t/adding-threshold-band-to-box-and-whisker-chart/40394/1 "2020-11-06T14:53:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [January 28, 2021, 8:32am UTC](https://forum.inductiveautomation.com/t/adding-threshold-band-to-box-and-whisker-chart/40394/2 "2021-01-28T08:32:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [April 12, 2021, 3:35am UTC](https://forum.inductiveautomation.com/t/adding-threshold-band-to-box-and-whisker-chart/40394/3 "2021-04-12T03:35:35Z")

</div>

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:**

```auto
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:**

```auto
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:**

```auto
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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9c9d9c63a2c0006893ff630e204b8cadef5a7e88.png)
