Tooltip Behavior
-
- Posts: 8
- Joined: Thu Mar 20, 2003 7:45 pm
Tooltip Behavior
Hi,
Currently, tooltips appear on JFreeChart line charts when you hover your mouse cursor over a vertex. Our users complain that they have a hard time getting them to pop up because this hot spot is so small. Other charting packages address this by making the hot zone be the entire line segment between vertices, inclusive. I think in some cases the hot zone also extends vertically above and below the charted lines for some distance as well. Is it possible to extend the tooltip behavior to something a little less restrictive?
Fran
Currently, tooltips appear on JFreeChart line charts when you hover your mouse cursor over a vertex. Our users complain that they have a hard time getting them to pop up because this hot spot is so small. Other charting packages address this by making the hot zone be the entire line segment between vertices, inclusive. I think in some cases the hot zone also extends vertically above and below the charted lines for some distance as well. Is it possible to extend the tooltip behavior to something a little less restrictive?
Fran
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Hi Fran,
The "hotspot" for the tooltip is the region used for the ChartEntity created by the renderer (whichever renderer you are using) in the drawItem(...) method. At the moment, the LineAndShapeRenderer is just using the Shape that it drew as the hotspot, and ignoring the lines. But it would be a useful enhancement to provide an option to increase the size of this area. I'll add it to the to-do list.
Regards,
Dave Gilbert
The "hotspot" for the tooltip is the region used for the ChartEntity created by the renderer (whichever renderer you are using) in the drawItem(...) method. At the moment, the LineAndShapeRenderer is just using the Shape that it drew as the hotspot, and ignoring the lines. But it would be a useful enhancement to provide an option to increase the size of this area. I'll add it to the to-do list.
Regards,
Dave Gilbert
-
- Posts: 21
- Joined: Fri Sep 30, 2005 4:00 am
- Location: Malaysia
- Contact:
kianfatt1982
this in the todo list is it already done, if it is where is the updates how to I increase the area or decrease the area, please give me some light on this
kianfatt1982@gmail.com
kianfatt1982@gmail.com
-
- Posts: 17
- Joined: Tue Oct 11, 2005 9:27 pm
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
There is a method setDefaultEntityRadius() that controls the size of the circle around the (x, y) location that is used as the default "hotspot". The behaviour depends a little on the specific renderer though - for example, the XYLineAndShapeRenderer will only use the default hotspot if shapes are not visible (if they are visible, the shape itself is used as the hotspot). So if you are having a problem with a specific renderer, please say which one and I'll take a closer look.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 17
- Joined: Tue Oct 11, 2005 9:27 pm
Hi Mr. Gilbert,
thanks for your time.
i am dealing with the XYItemRenderer and i want the tool tip to be shown when i move the mouse over the line that is drawn between the 2 data points. Unfortunately, setDefaultEntityRadius() will not help me much as this just increases the hotspot area around the data point. I am trying to Pass the line, that is drawn between the 2 data points as a Shape for the XYItemEntity(I created a class Line2D.Double using the 2 data points ), but for some reason this is not working. do you think if i create a Polygon using the points around this line and pass it to the XYItemEntity do you think i can make a whole line between the data points an entity area?
Also, if i click the mouse on the chart, how can i find out the nearest data point?
Please help.
thanks,
vani
thanks for your time.
i am dealing with the XYItemRenderer and i want the tool tip to be shown when i move the mouse over the line that is drawn between the 2 data points. Unfortunately, setDefaultEntityRadius() will not help me much as this just increases the hotspot area around the data point. I am trying to Pass the line, that is drawn between the 2 data points as a Shape for the XYItemEntity(I created a class Line2D.Double using the 2 data points ), but for some reason this is not working. do you think if i create a Polygon using the points around this line and pass it to the XYItemEntity do you think i can make a whole line between the data points an entity area?
Also, if i click the mouse on the chart, how can i find out the nearest data point?
Please help.
thanks,
vani
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Yes that will work. There is a method in JCommon (ShapeUtilities.createLineRegion()) that might help there.vani_hegde wrote:do you think if i create a Polygon using the points around this line and pass it to the XYItemEntity do you think i can make a whole line between the data points an entity area?
There isn't a general purpose method in JFreeChart to do that. The cross hair code does it, but not in a way that is easy to access. You need to take the mouse coordinates on the screen, convert those to Java2D coordinates, then to chart coordinates, then iterate through your dataset to find which item is "closest". It isn't straightforward, but it's not impossible either.vani_hegde wrote:Also, if i click the mouse on the chart, how can i find out the nearest data point?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 17
- Joined: Tue Oct 11, 2005 9:27 pm
Interpolating between points on a StackedXYAreaRenderer
I had some luck with extrapolating from this post with a StackedXYAreaRenderer and chart that I was trying to get interpolated values between datapoints. It was a bit of a hack. I had to have access to data that would allow me to interpolate once I had the X data value in the chart. I also needed to somehow get a tie back to get the exact series when mousing over a region in the StackedXYArea chart, so I could tie it back to the data I created the DefaultXYAreaTable out of.
To do this I first copied the source of the StackedXYAreaRenderer and made a new class out of it and altered the drawItem method.
I moved the XYItemEntity creation in the chart from the 2nd pass (pass==1)_ in the drawItem code to the bottom of the 1st pass (pass==0). And changed the shape passed in the item as suggested by Vani. Here's the code:
This allows the mouse over to find an entity with the shape of the whole series in the chart. This allowed me to get the series num and name to tie back to my interpolating data.
Next I overloaded the getToolTipText() method in my ChartPanel derivative with this code.
Hope this makes sense.
To do this I first copied the source of the StackedXYAreaRenderer and made a new class out of it and altered the drawItem method.
I moved the XYItemEntity creation in the chart from the 2nd pass (pass==1)_ in the drawItem code to the bottom of the 1st pass (pass==0). And changed the shape passed in the item as suggested by Vani. Here's the code:
Code: Select all
code:
// collect entity and tool tip information...
if ((state.getInfo() != null) && (item > 0) && (item == itemCount - 1)) {
EntityCollection entities = state.getEntityCollection();
Shape seriesShape = areaState.getSeriesArea();
if (entities != null && seriesShape != null && !nullPoint) {
//if (entities != null && seriesShape != null) {
String tip = null;
XYToolTipGenerator generator
= getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series,
item);
}
//Now the entity has the entire shape of the series to get mouse over.
XYItemEntity entity = new XYItemEntity(seriesShape, dataset,
series, item, tip, url);
entities.add(entity);
}
}
Next I overloaded the getToolTipText() method in my ChartPanel derivative with this code.
Code: Select all
code:
public String getToolTipText(MouseEvent e) {
String retString = null; // super.getToolTipText(e);
EntityCollection entities = null;
ChartRenderingInfo info = getChartRenderingInfo();
if (info != null) {
Insets insets = getInsets();
entities = this.getChartRenderingInfo().getEntityCollection();
int xPos = (int) ((e.getX() - insets.left) / this.getScaleX());
int yPos = (int) ((e.getY() - insets.top) / this.getScaleY());
//ChartEntity entity = entities.getEntity(xPos,yPos);
XYItemEntity entity = (XYItemEntity) entities.getEntity(xPos,yPos);
if (entity != null) {
Point2D p = translateScreenToJava2D(e.getPoint());
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
XYPlot plot = (XYPlot)chart.getPlot();
if(plot == null) {
return null;
}
//XYItemEntity xyEntity = (XYItemEntity) entity;
String seriesName = entity.getDataset().getSeriesKey(entity.getSeriesIndex()).toString();
ValueAxis domainAxis = this.plot.getDomainAxis();
RectangleEdge domainAxisEdge = this.plot.getDomainAxisEdge();
double chartX = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge);
ValueAxis rangeAxis = plot.getRangeAxis();
double chartY = 0.0d;
//RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
//double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge);
//Get the exact chart Y from the data that you derived the
//datapoints from. This allows the display of the tool tip for all the
//top lines of each region in the StackXYArea chart.
chartY = converter.getValueForSeriesPoint(chartX);
}
retString = seriesName + "-H(" + chartX + ") = " + formatYValue(chartY) ;
}
}
return retString;
}
Hi i had tried with the following codedavid.gilbert wrote:There is a method setDefaultEntityRadius() that controls the size of the circle around the (x, y) location that is used as the default "hotspot". The behaviour depends a little on the specific renderer though - for example, the XYLineAndShapeRenderer will only use the default hotspot if shapes are not visible (if they are visible, the shape itself is used as the hotspot). So if you are having a problem with a specific renderer, please say which one and I'll take a closer look.
renderer.setToolTipGenerator((XYToolTipGenerator) new StandardXYToolTipGenerator());
renderer.setURLGenerator((XYURLGenerator) new StandardXYURLGenerator("#","",""));
renderer.setDefaultEntityRadius(4);
But it is not working. Can you please help me in this!