# XYDifferenceRenderer change outline color

**URL:** <https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [July 18, 2022, 2:37pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007 "2022-07-18T14:37:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 18, 2022, 2:37pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/1 "2022-07-18T14:37:53Z")

</div>

Hi,

In Report Module, I created script below to color area between 2 lines :

Is it possible to change outlines color ? Dash pattern and width too ?

```auto
from java.awt import BasicStroke, Color
from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	
renderer=XYDifferenceRenderer(Color(0, 255, 0, 127), Color(255,71,71,127), 0)
chart.getXYPlot().setRenderer(renderer)

```

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 18, 2022, 3:56pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/2 "2022-07-18T15:56:21Z")

</div>

Can you tag your post as _Vision_ or _Perspective_ to help guys like me that get confused? Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2022, 4:24pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/3 "2022-07-18T16:24:30Z")

</div>

> [@flavien](#):
>
> ```auto
> from java.awt import BasicStroke, Color
> from org.jfree.chart.renderer.xy import XYDifferenceRenderer
> 
> ```

Those are a flare-lit tipoff that this is not Perspective. They apply to both Vision and Reporting.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 18, 2022, 8:01pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/4 "2022-07-18T20:01:13Z")

</div>

Apparently the outlines are drawn based on the Series Color so you can change it using the `setSeriesPaint()`

```python
from java.awt import BasicStroke, Color
from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	
renderer=XYDifferenceRenderer(Color(0, 255, 0, 127), Color(255,71,71,127), 0)
renderer.setSeriesPaint(Color.BLACK) #or whatever color you want
chart.getXYPlot().setRenderer(renderer)

```

For the dash pattern and width I imagin you would need to build a BasicStrok and then use `rendere.setSeriesStroke(yourBasicStroke)`

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 19, 2022, 7:18am UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/5 "2022-07-19T07:18:28Z")

</div>

With my script :  
Area between lines is colored but default lines colors are used

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/3/f303f76eb92e169cc4e063ae9f2040fcf6c113ce.png)

With your scipt @lrose :  
Area not colored and lines colored with my own pens.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/f/6fdfcc198c718f75ca63d7bac1681c5951666e0a.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 19, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/6 "2022-07-19T14:18:46Z")

</div>

That’s what I get for just posting the code off the top of my head.

```auto
	from java.awt import BasicStroke, Color
	from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	
	renderer = XYDifferenceRenderer(Color(0,255,0,127), Color(255,71,71,127),0)
	#This loop will set all of the series colors to black, the important thing is that
	#you have to specifiy the series index in the call to setSeriesPaint
	for series in range(chart.getXYPlot().getSeriesCount()):
		renderer.setSeriesPaint(series,Color.BLACK)
	
	#This code sets up a Dashed Stroke, you don't need to store them all in variables
	#like this but I wanted to be explicit so you knew what was what.
	width = 2.0
	cap = BasicStroke.CAP_BUTT
	join = BasicStroke.JOIN_BEVEL
	miterlimit = 10.0
	dashArray = [3.0,3.0]
	dashPhase = 0
	stroke = BasicStroke(width,cap,join,miterlimit,dashArray,dashPhase)
	#this sets the stroke for series 1, series index is zero based and depends on how the dataset
	#is configured so you may need to play with the index to get what you're looking for.
	renderer.setSeriesStroke(1,stroke)

	#now set the plot's renderer 
	chart.getXYPlot().setRenderer(renderer)

```

The reason why my original code didn’t work is because `setSeriesPaint()` takes two arguments and I only provided 1, so the configureChart function was erroring resulting in the renderer not being set, so the default renderer remained.

This code I believe should demonstrate what you need to get the outcome you’re looking for.

If you want to have the stroke change based on the difference then you would have to sub class the XYDifferenceRenderer class, doable, but not exactly trivial.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 20, 2022, 9:10am UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/7 "2022-07-20T09:10:30Z")

</div>

Hi,

Thanks for your code.  
Now the chart colors area under my first serie. 🙃  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/00d3f822d96956f15699bb899ed80d22631c4b15.png)

My code :

```auto
from java.awt import BasicStroke, Color
from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	
renderer=XYDifferenceRenderer(Color(0, 200, 83, 127), Color(255,23,68,127), 0)
	
width = 1.0
cap = BasicStroke.CAP_BUTT
join = BasicStroke.JOIN_BEVEL
miterlimit = 10.0
dashArray = [2,5]
dashPhase = 0
stroke0 = BasicStroke(2.0)
stroke1 = BasicStroke(width,cap,join,miterlimit,dashArray,dashPhase)
	
renderer.setSeriesPaint(0,Color(0,145,234))
renderer.setSeriesPaint(1,Color(255,23,68))
renderer.setSeriesStroke(0,stroke0)
renderer.setSeriesStroke(1,stroke1)
	
chart.getXYPlot().setRenderer(renderer)

```

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 20, 2022, 9:44am UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/8 "2022-07-20T09:44:17Z")

</div>

To resolve this issue we deleted manually all pens in chart properties and recreate them. We only changed key and axis attribution.  
Strange 🤔

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 20, 2022, 12:30pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/9 "2022-07-20T12:30:35Z")

</div>

Is it possible to change Pen Names and Axis label in my script ?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 20, 2022, 12:46pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/10 "2022-07-20T12:46:24Z")

</div>

It is possible, easier to do it at dataset creation.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [July 20, 2022, 12:48pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/11 "2022-07-20T12:48:50Z")

</div>

Do you have an example in python ? It’s for Module report.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 20, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/12 "2022-07-20T14:05:04Z")

</div>

Report module or standard chart, isn’t really applicable here. Somewhere you are generating the dataset for the chart. The best practice would be to change the names there. By default whatever the column names of the dataset are is what the Legend Item Labels will be. I would recommend doing this that way, as then it is straight forward and not hidden away in a configuration script.

However, it is possible to do this in script. You have to subclass `XYSeriesLabelGenerator` and then through some method provide a new label. Here I am just using a dictionary to map from the old labels to the new labels.

```auto
	from java.awt import BasicStroke, Color
	from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	from org.jfree.chart.labels import XYSeriesLabelGenerator
	
	renderer=XYDifferenceRenderer(Color(0, 200, 83, 127), Color(255,23,68,127), 0)
		
	stroke0 = BasicStroke(2.0)
	stroke1 = BasicStroke(1.0,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL,10.0,[2.0,5.0],0)
		
	renderer.setSeriesPaint(0,Color(0,145,234))
	renderer.setSeriesPaint(1,Color(255,23,68))
	renderer.setSeriesStroke(0,stroke0)
	renderer.setSeriesStroke(1,stroke1)
	
	class customXYSeriesLabelGenerator(XYSeriesLabelGenerator):
		__newLabelMap = {'Old Series 0 Label':'New Series 0 Label','Old Series 1 Label':'New Series 1 Label'}
	
		def generateLabel(self,dataset,series):
			#the Series Key is the "Old Label"
			key = dataset.getSeriesKey(series)
			#insure that the key exists in the newLabelMap, if not just return the original name
			if key in self.__newLabelMap.keys():
				return self.__newLabelMap[key]
			return key
	#Create an instance of your Label Generator and set the LegendItemLabelGenerator of the renderer to use the new labels.
	renderer.setLegendItemLabelGenerator(customXYSeriesLabelGenerator())

	chart.getXYPlot().setRenderer(renderer)
```

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [September 14, 2022, 9:47am UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/13 "2022-09-14T09:47:38Z")

</div>

Hi,  
I observed color problems in few charts.  
Majority are good but others are wrong like below.  
How is it possible ?  
Bars could be responsible of that ?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/8/382e7a701385f17a92f0865d58dab568345eaff3.png)  
Normally chart below should be entirely red.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/4388330f2656121378ba9ec717d1fd482aba6a1b.png)

My script :

```auto
from java.awt import BasicStroke, Color
from org.jfree.chart.renderer.xy import XYDifferenceRenderer
	
renderer=XYDifferenceRenderer( Color(255,138,101,127),Color(129, 199, 132, 127), 0)
	
width = 1.0
cap = BasicStroke.CAP_SQUARE
join = BasicStroke.JOIN_BEVEL
miterlimit = 10.0
dashArray = [2,5]
dashPhase = 0
stroke0 = BasicStroke(2.0)
stroke1 = BasicStroke(width,cap,join,miterlimit,dashArray,dashPhase)
	
renderer.setSeriesPaint(0,Color(0,145,234))
renderer.setSeriesPaint(1,Color(255,23,68))
renderer.setSeriesStroke(0,stroke0)
renderer.setSeriesStroke(1,stroke1)
	
chart.getXYPlot().setRenderer(renderer)
	
chart.getXYPlot().getRangeAxis(0).setLabel(data['influencerTitle'])

```

Thanks

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 14, 2022, 11:13am UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/14 "2022-09-14T11:13:56Z")

</div>

Well, it’s hard to say, as nothing you are doing in your script is actually controlling that behavior. That is controlled by the Renderer. You may need to look for some answers elsewhere, in relation to the Jfree Chart’s XYDifferenceRenderer.

If you remove the bars, does that change the behavior? I wouldn’t expect it to.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [September 14, 2022, 2:02pm UTC](https://forum.inductiveautomation.com/t/xydifferencerenderer-change-outline-color/62007/15 "2022-09-14T14:02:19Z")

</div>

Without bars problem is the same.  
🤔
