Easy Chart Pen ToolTips

@eckman.tech - I experimented with this, and I was able to manipulate the format of an easy chart's tool tips using a button's actionPerformed event handler. It should be easy to modify the method for any usage case. Here is the code:

from org.jfree.chart.labels import StandardXYToolTipGenerator
renderer = event.source.parent.getComponent('Easy Chart').getComponent(0).getComponent(0).chart.getPlot().getRenderer()
xFormat = renderer.getBaseToolTipGenerator().getXFormat().getInstance()
yFormat = renderer.getBaseToolTipGenerator().getYFormat().getInstance()
xFormat.applyPattern("00.0#")
renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator("{2}% Full", yFormat, xFormat))

Tool tip before edit:
image

Tool tip after edit:
image

The key is the is the first field in the StandardXYToolTipGenerator. Using reflection, I was able to determine that the DEFAULT_TOOLTIP_FORMAT = "{0}: ({1}, {2})" where {0} is the field, {1} is the y axis, and {2} is the x axis.

The format string behaves like a MessageFormat, but for the xFormat, you will have to modify the format using the methods in java.txt.NumberFormat prior to applying the tool tip generator. Likewise the yFormat will have to be modified using the methods in java.text.DateFormat.

Finally, the getRenderer() method does not apply to all plots, so if you are using a piePlot for example, simply omit it, and use a StandardPieToolTipGenerator instead of a StandardXYToolTipGenerator:

toolTipGenerator = event.source.parent.getComponent('Easy Chart').getComponent(0).getComponent(0).chart.getPlot().getToolTipGenerator()
#	.getLabelFormat() = {0}: ({1}, {2})
#	.getNumberFormat() = java.text.DecimalFormat
#	.getPercentFormat() = java.text.DecimalFormat

1 Like