Jfree chart - click on rendered data point

This should do the trick:

from org.jfree.chart import ChartMouseListener

class CustomChartMouseListener(ChartMouseListener):
     def chartMouseClicked(self,e):
          xyItem = e.getEntity() #gets the data entity that was clicked, None if no entity was clicked
          if xyItem: #ensure that a data entity was clicked
               dataset = xyItem.getDataset()
               xValue = dataset.getXValue(xyItem.getSeriesIndex(),xyItem.getItem())
               yValue = dataset.getYValue(xyItem.getSeriesIndex(),xyItem.getItem())

               system.nav.openWindow('YourPopupWindowClass',{'yValueParameterName':xValue,'yValueParameterName':yValue})

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

self.addChartMouseListener(CustomChartMouseListener())
4 Likes