# Bar chart with crosshatch pattern

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936>\
**Category:** Ignition\
**Created:** [April 22, 2021, 10:33pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936 "2021-04-22T22:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dillon.hoefener](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@dillon.hoefener](https://forum.inductiveautomation.com/u/dillon.hoefener)\
**Post date:** [April 22, 2021, 10:33pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936/1 "2021-04-22T22:33:36Z")

</div>

Would anyone happen to have an example of a method for displaying a crosshatch pattern in a bar of a bar chart? I couldn’t find a way to configure this in the designer short of an extension function, but I didn’t have any luck finding anything useful in the JFreeChart API docs. I see this _might_ be possible using java.awt.TexturePaint, but I haven’t had success with this.

Any help or tips would be much appreciated!

---

<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:** [April 22, 2021, 10:37pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936/2 "2021-04-22T22:37:51Z")

</div>

> [@Change colour of item in Chart](http://forum.inductiveautomation.com/t/change-colour-of-item-in-chart/35729/6):
>
> from java.awt import Color from org.jfree.chart.renderer.xy import XYLineAndShapeRenderer from java.awt.geom import Rectangle2D chart = event.source.parent.getComponent('Chart').getChart() ucl = 58.0 plot = chart.getPlot() class MyRenderer(XYLineAndShapeRenderer): def getItemPaint(self,series,row): if series == 0 and plot.getDataset(0).getYValue(series, row) \> ucl: return Color.RED else: return Color.BLUE renderer = MyRenderer() renderer.setSeriesLinesVisible(0,False) renderer.s…

This might get you started.

---

<div class="post-metadata">

**Author:** ![dillon.hoefener](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@dillon.hoefener](https://forum.inductiveautomation.com/u/dillon.hoefener)\
**Post date:** [April 28, 2021, 2:13pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936/3 "2021-04-28T14:13:44Z")

</div>

Thanks @paul-griffith. I was able to color the bars through configureChart, but I’m having trouble with the TexturePaint class. The API docs show that renderer.setSeriesPaint() accepts a TexturePaint object as a color, but when I am assigning the TexturePaint to the the series color, the chart is not rendering the pattern.

Can you please take a look at my code and let me know where I’m going wrong with this (series 1 is what I’m having trouble with, series 0 paint is working as expected)?

Thanks

```auto
	from java.awt import Color, Graphics2D, TexturePaint
	from java.awt.image import BufferedImage
	from java.awt.geom import Rectangle2D
	
	plot = chart.getCategoryPlot()
	renderer = plot.getRenderer(1)
	ds = chart.getPlot().getDataset(1)
	hourVal = self.Data.getValueAt(0,1)
	targetVal = self.Data.getValueAt(0,2)
	
	#paint actual bar color based on performance to target
	plot = chart.getCategoryPlot()
	renderer = plot.getRenderer(1)
	ds = chart.getPlot().getDataset(1)
	otsVal = self.Data.getValueAt(0,1)
	targetVal = self.Data.getValueAt(0,2)

	if hourVal >= targetVal:
		renderer.setSeriesPaint(0, Color.GREEN)
	else:
		renderer.setSeriesPaint(0, Color.RED)

	#paint series 1 with textured image
	bufferedImage = BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB)
	g2 = bufferedImage.createGraphics()
	g2.setColor(Color.WHITE)
	g2.fillRect(0, 0, 5, 5)
	g2.setColor(Color.GRAY)
	g2.drawLine(0, 0, 5, 5)
	g2.drawLine(5, 5, 0, 0)
	g2.drawLine(0, 5, 5, 0)
	rect = Rectangle2D.Double(0, 0, 5, 5)
	texturePaint = TexturePaint(bufferedImage, rect)
	
	renderer.setSeriesPaint(1, texturePaint)

```

---

<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:** [April 28, 2021, 4:11pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936/4 "2021-04-28T16:11:54Z")

</div>

Does setting a solid color to series 1 work as expected? That is - is the issue with series 0 vs 1, or is the issue with your `TexturePaint` creation? If it’s the former, then do you have multiple subplots on your chart? JFreeChart requires you to step through subplots manually, which _may_ be affecting things.

---

<div class="post-metadata">

**Author:** ![dillon.hoefener](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@dillon.hoefener](https://forum.inductiveautomation.com/u/dillon.hoefener)\
**Post date:** [May 9, 2021, 3:53pm UTC](https://forum.inductiveautomation.com/t/bar-chart-with-crosshatch-pattern/45936/5 "2021-05-09T15:53:04Z")

</div>

Yes, the solid color works as expected. The issue is only with the TexturePaint creation. There are not multiple subplots being used.

Sorry for delayed response, I thought I might be able to respond to the email I got. Thanks
