Adding tooltips to YIntervalRenderer

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
bevis
Posts: 4
Joined: Mon Jun 15, 2015 3:33 pm
antibot: No, of course not.

Adding tooltips to YIntervalRenderer

Post by bevis » Tue Jun 30, 2015 9:06 am

I'm using a YIntervalRenderer and would like to enable tooltips on the high & low points.
I gather that they have not been implemented for this renderer, so I've been trying to work out how to do it, but am having difficulties understanding the process.
Following the logic in createScatterPlot(), I set up my renderer as:

YIntervalRenderer renderer = new YIntervalRenderer();
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

but it seems I need more than that. Looking at XYLineAndShapeRenderer as an example I can't see what I'm missing?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Adding tooltips to YIntervalRenderer

Post by paradoxoff » Wed Jul 01, 2015 5:05 pm

After checking the source, I think that this is a bug in the YIntervalRenderer class. The class is using the bounds of the line between the minimum and maximum y value as hot spot in which eventual mouse events are captured.
Since the bounds will be a mathematical line with either a height or a width of zero, the mouse can never really be within the bounds of the hot spot.
To fix that, you could try to change the line 242 (I am referring to the current JFreeChart version) of YIntervalRenderer and replace

Code: Select all

addEntity(entities, line.getBounds(), dataset, series, item, 0.0,
with

Code: Select all

addEntity(entities, ShapeUtilities.createLineRegion(line,4.0f), dataset, series, item, 0.0,
I you have still trouble to hit the entity with the mouse, just use a larger value than 4.0f.

bevis
Posts: 4
Joined: Mon Jun 15, 2015 3:33 pm
antibot: No, of course not.

Re: Adding tooltips to YIntervalRenderer

Post by bevis » Thu Jul 02, 2015 10:45 am

That worked, thanks very much!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Adding tooltips to YIntervalRenderer

Post by david.gilbert » Thu Sep 10, 2015 5:46 am

I committed this fix for inclusion in the upcoming 1.0.20 release.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked