Tooltip Behavior

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Fran Tonello
Posts: 8
Joined: Thu Mar 20, 2003 7:45 pm

Tooltip Behavior

Post by Fran Tonello » Fri Mar 21, 2003 2:16 am

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

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

Post by david.gilbert » Fri Mar 21, 2003 12:52 pm

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

Fran Tonello
Posts: 8
Joined: Thu Mar 20, 2003 7:45 pm

Post by Fran Tonello » Sat Mar 22, 2003 1:02 am

That's great! Thanks!

kianfatt1982
Posts: 21
Joined: Fri Sep 30, 2005 4:00 am
Location: Malaysia
Contact:

kianfatt1982

Post by kianfatt1982 » Fri Sep 30, 2005 7:54 am

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
Ting Kian Fatt
(Software Engineer)
kianfatt1982@gmail.com

vani_hegde
Posts: 17
Joined: Tue Oct 11, 2005 9:27 pm

Post by vani_hegde » Mon Oct 24, 2005 11:21 pm

Hi Mr. Gilbert,
i was wondering if this feature will be included in the upcoming release?
If so, when would be the next release? We need this feature and if the regular release which inclues this feature is far away, i need to do this implementaion myself. Any tips for the same?

thanks,
vani

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

Post by david.gilbert » Tue Oct 25, 2005 10:02 am

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

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

vani_hegde
Posts: 17
Joined: Tue Oct 11, 2005 9:27 pm

Post by vani_hegde » Tue Oct 25, 2005 11:07 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

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

Post by david.gilbert » Wed Oct 26, 2005 9:58 am

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?
Yes that will work. There is a method in JCommon (ShapeUtilities.createLineRegion()) that might help there.
vani_hegde wrote:Also, if i click the mouse on the chart, how can i find out the nearest data point?
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.
David Gilbert
JFreeChart Project Leader

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

vani_hegde
Posts: 17
Joined: Tue Oct 11, 2005 9:27 pm

Post by vani_hegde » Wed Oct 26, 2005 9:02 pm

Thanks Mr. Gilbert for your help,
I got this working. Now have the hotspot created around the line and i can get the tooltip if the mouse moves over line and also if the user clicks on the line i can show the information about the series etc.

Rgds,
vani

Craig

Post by Craig » Tue Nov 08, 2005 6:31 pm

Hi Vani, can you post the code you wrote to do this?
Thx
Craig

notme
Posts: 4
Joined: Tue Mar 07, 2006 1:29 am

Post by notme » Thu Mar 16, 2006 1:12 am

Hi Vani - I'd be interested in any code you care to share too... Thanks.

MadDog
Posts: 1
Joined: Fri Sep 28, 2007 5:52 pm

Interpolating between points on a StackedXYAreaRenderer

Post by MadDog » Fri Sep 28, 2007 6:20 pm

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:

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);
              }
          }
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.

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;
  }

Hope this makes sense.

raju
Posts: 3
Joined: Mon Dec 10, 2007 11:02 am

Post by raju » Wed Dec 12, 2007 11:07 am

david.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.
Hi i had tried with the following code

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!

Locked