Vision Chart - Category Chart & XTrace

So, this post from lrose and this one from Travis were very helpful in getting something working on the chart with only the category bars.

from org.jfree.chart import ChartMouseListener
from org.jfree.chart.annotations import CategoryTextAnnotation
	
chartObject = self
	
class CustomChartMouseListener(ChartMouseListener):
	def chartMouseMoved(self,e):
		pass
	def chartMouseClicked(self,e):
		# Get plot, remove previous annotations
		plot = chart.getPlot()
		plot.clearAnnotations()
		
		# get chart data & create annotation
		if e.getEntity(): 
			# Get dataset(s)
			dataset = chartObject.b_MonthlyWater
			colNames = dataset.getColumnNames()
			ds = system.dataset.toPyDataSet(dataset)
			
			# Wrap in try to prevent error clicking on axis
			try:
				# Get category from entity
				category = e.getEntity().columnKey
				for row in ds:
					if row[0] == category:
						rData = (row[1], row[2])
						y = max(rData)+100 #offset so annotation is above tallest bar
				
				# Add annotation
				annoStr = str(colNames[1])+": "+str(int(rData[0]))+", "+str(colNames[2])+": "+str(int(rData[1]))
				plot.addAnnotation(CategoryTextAnnotation(annoStr, category, y))
			
			except:
				pass
	
# Ensure only 1 listener running
for listener in self.getListeners(ChartMouseListener):
     self.removeChartMouseListener(listener)
	
# Run listener
self.addChartMouseListener(CustomChartMouseListener())

A couple outstanding issues:

  • Adding the xy category overlay breaks the function, and clicking on the chart will not produce annotations.
  • Documentation suggests the annotations will support HTML, but as of yet I've been unable to produce a multi-line entry.

Will update as I progress.