# Jfree chart - click on rendered data point

**URL:** <https://forum.inductiveautomation.com/t/jfree-chart-click-on-rendered-data-point/38066>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 25, 2020, 6:29pm UTC](https://forum.inductiveautomation.com/t/jfree-chart-click-on-rendered-data-point/38066 "2020-08-25T18:29:20Z")\
**Posts on this page:** 1\
**Showing post:** 20

<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:** [March 20, 2021, 3:31pm UTC](https://forum.inductiveautomation.com/t/jfree-chart-click-on-rendered-data-point/38066/20 "2021-03-20T15:31:52Z")

</div>

> [@prasath.t](#):
>
> staked bar has different colors . when i select a color. i what to highlight the color outline - in order to show that is selected. i have attached my script also
> 
> is possible to do?

Yeah.

One way to do it is to create an annotation, it would be a little simpler if you were using an XYPlot as you could just use a XYShapeAnnotation, however, since you're using a bar chart that is a CategoryPlot so you need to create a custom annotation. Still not extremely complicated but not exactly straightforward either.

Add the following to you're configureChart extension function

```auto
from org.jfree.chart import ChartMouseListener
from org.jfree.chart.annotations import CategoryAnnotation
from java.awt import Color, BasicStroke

class CategoryShapeAnnotation(CategoryAnnotation):
	def __init__ (self,newShape):
		self.shape = newShape

	def draw(self,g2,plot,dataArea,domainAxis,rangeAxis):
		#set the color that you want to highlight the item with
		#g2.setColor(Color.YELLOW) #to use a preset color constant
		g2.setColor(Color(1.0,1.0,0.0,1.0)) #to use a custom color with alpha
		#set the size of the stroke.
		g2.setStroke(BasicStroke(4.0))
		g2.draw(self.shape)
		
class CustomChartMouseListener(ChartMouseListener):
	def chartMouseMoved(self,e):
		pass
	def chartMouseClicked(self,e):
	    #verify that an entity was clicked on
		if e.getEntity():
			plot = e.getChart().getPlot()
			entityBounds = e.getEntity().getArea().getBounds2D()
			for a in plot.getAnnotations():
				#there should only ever be 1 annotation
				a.shape = entityBounds
				break
			else:
			    #if the annotation does not exist yet create it
				plot.addAnnotation(CategoryShapeAnnotation(e.getEntity().getArea().getBounds2D()))

for listener in self.getListeners(ChartMouseListener):
	self.removeChartMouseListener(listener)
	
self.addChartMouseListener(CustomChartMouseListener())

```

This will work for any categoryPlot.

---

_[View the full topic](https://forum.inductiveautomation.com/t/jfree-chart-click-on-rendered-data-point/38066)._
