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.
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.
Pretty much no progress since last post. I tried a couple alternate approaches to rendering the x-trace, but to no avail.
I left off having Category Bar annotations, but introducing the Category XY plot on top of the bar chart returns only the last data point for the XY plot at any given point (which is usually NaN due to the nature of the graph).
I ran into a skills wall, and with that ran out of free time to focus on this. The lack of experience with java is really killing me here. I can read the docs on the jfreechart and associated components all day and still not understand how properly to apply them.
I'm hoping to circle back after the backlog is reduced.
Can't say no to that! I've included 2 version of the chart.
"Chart Scripting" is the simplified chart I am using to test my scripting efforts to place an x-trace on the screen. With both plots enabled, it will not work (just shows December from the Category Line Renderer). Working with only the bar chart, the script should populate x-trace.
"Chart Export" is the complete chart I'd like to produce. Pie-in-the-sky goal is x-trace that shows values on all charts when any of the 4 subplots is clicked.