Vision Chart - Category Chart & XTrace

Hey folks,

TL:DR - Looking to add some xtrace function to Vision "Chart" component in "Category" mode. I expect this ask falls squarely into "java wizardry," but would appreciate any advice on how to proceed.

Working with the Vision Chart component, using the "Category Chart" setting to display monthly values with an average over the top of it, showing year to year usage variance.

I am looking to add some x-trace functionality so users can click on a point on the chart and get the data back for the nearest month (or whatever function can nearest approximate this).

It appears as though the "Show Popup" menu does not work in Category Chart mode, and with that, x-trace is unavailable. "Selection Enabled" also appears to not work. "Show Tooltips" shows this less-than-helpful bit of information.

I've tried scripting some xtrace functionality following Justin's advice, but to no avail. Following jpark's advice I am able to get values for one of the two datasets. However, this falls apart when I add additional subplots.

Corresponding datasets for reference:

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.