# Chart set bar width on stacked

**URL:** <https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636>\
**Category:** General Discussion\
**Created:** [August 21, 2019, 1:54pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636 "2019-08-21T13:54:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimschaefer](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jimschaefer](https://forum.inductiveautomation.com/u/jimschaefer)\
**Post date:** [August 21, 2019, 1:54pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636/1 "2019-08-21T13:54:34Z")

</div>

I used the chart tool to create a stacked bar chart. I cannot figure out how to set the width of the bar with any functions I try in the configureChart extension function. Does anyone know how to do this ?  
When I make the entire object narrower in the designer it makes the text to small in the legend.  
Here is the code I have in the configureChart extention function for setting legend font, getting rid of the gradient, shadow and background grid:

```auto
def configureChart(self,chart):
	from java.awt import Color
	from org.jfree.chart.renderer.category import StandardBarPainter
	from java.awt import Font
	
	darkColor = Color(43,43,43)	
	lightColor = Color(213,213,213)
	
	plot = chart.getPlot()
	legend = chart.getLegend()
	
	chart.setBackgroundPaint(darkColor)
	
	plot.setBackgroundPaint(darkColor)
	plot.setDomainGridlinesVisible(0) #turn off background grid lines
	plot.setRangeGridlinesVisible(0) #turn off background grid lines
	plot.setOutlineVisible(0) #turn off background outline
	
	legend.setBackgroundPaint(darkColor)
	legend.setItemPaint(lightColor) # sets font color in legend
	d = Font("Dialog", Font.BOLD, 14) 
	legend.setItemFont(d) #sets font in legend
	legend.setBorder(0, 0, 0, 0) #removes the legend border
	
	#removes the gradient rendering of bars and replaces with single colors
	renderer = plot.getRenderer()
	renderer.setBarPainter(StandardBarPainter())
	renderer.setShadowVisible(0) #removes shadow on bars
	
	#these functions didn't work, error reported these methods didn't exist or they had no effect
#	renderer.setMaximumBarWidth(1)
#	renderer.setMaximumBarWidth(5)
#	renderer.setSeriesBarWidth(2,4)

```

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4f06f2d451a054e3c2e61f336e1a719b0e62b5ac.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 21, 2019, 3:30pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636/2 "2019-08-21T15:30:30Z")

</div>

Looking into it, it looks like you need to provide a custom subclass of `StandardBarPainter` - you’ll notice [`StandardBarPainter`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/StandardBarPainter.html) calls `paintBar` with a [`BarRenderer`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/BarRenderer.html) - and that `BarRenderer` has a `getMaximumBarWidth()` method you could override.

---

<div class="post-metadata">

**Author:** ![jimschaefer](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jimschaefer](https://forum.inductiveautomation.com/u/jimschaefer)\
**Post date:** [August 22, 2019, 4:14pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636/3 "2019-08-22T16:14:21Z")

</div>

I am still very new to using jython and external libraries. Can you provide a quick example ?  
Thanks

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 22, 2019, 4:23pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636/4 "2019-08-22T16:23:55Z")

</div>

Actually, looking at it again, your commented out code should work fine - you're just missing one aspect - the `setMaximumBarWidth` function expects you to pass a _double_, which will be a percentage used:

> Sets the maximum bar width, which is specified as a percentage of the available space for all bars

Try passing `0.1` or `0.2` and see if you notice a difference in the final chart.

---

<div class="post-metadata">

**Author:** ![jimschaefer](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jimschaefer](https://forum.inductiveautomation.com/u/jimschaefer)\
**Post date:** [August 22, 2019, 4:39pm UTC](https://forum.inductiveautomation.com/t/chart-set-bar-width-on-stacked/27636/5 "2019-08-22T16:39:45Z")

</div>

That worked thanks. I added the lineb below which resulted in the graph below. Now to figure out how to get rid of the little gray line at the top…

`	renderer.setMaximumBarWidth(0.2) #value must be double and is a normalized percentage range 0 to 1`

The complete code:

```auto
def configureChart(self, chart):
	darkColor = Color(43,43,43)	
	lightColor = Color(213,213,213)
	
	plot = chart.getPlot()
	legend = chart.getLegend()
	
	chart.setBackgroundPaint(darkColor)
	
	plot.setBackgroundPaint(darkColor)
	plot.setDomainGridlinesVisible(0) #turn off background grid lines
	plot.setRangeGridlinesVisible(0) #turn off background grid lines
	plot.setOutlineVisible(0) #turn off background outline
	
	legend.setBackgroundPaint(darkColor)
	legend.setItemPaint(lightColor) # sets font color in legend
	d = Font("Dialog", Font.BOLD, 14) 
	legend.setItemFont(d) #sets font in legend
	legend.setBorder(0, 0, 0, 0) #removes the legend border
	
	from org.jfree.chart.renderer.category import BarRenderer
	from org.jfree.chart.renderer.category import StandardBarPainter
	
	#removes the gradient rendering of bars and replaces with single colors
	renderer = plot.getRenderer()
	print type(renderer)

	renderer.setBarPainter(StandardBarPainter())
	renderer.setShadowVisible(0)
	renderer.setMaximumBarWidth(0.2) #value must be double and is a normalized percentage range 0 to 1

```

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/bca4226a001bc6d73a17fcd513aa6626de3644fc.png)
