Continuous tooltip

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hcardoso3
Posts: 1
Joined: Tue Jul 02, 2019 7:49 pm
antibot: No, of course not.

Continuous tooltip

Post by hcardoso3 » Tue Jul 02, 2019 8:01 pm

Hello everyone,

I have been using JFreeChart to plot a 3 different graphics in the same panel in an SWT application. We calculate the different datasets for the graphs and display them horizontally and stack them vertically. Recently there was a need to display a tooltip on each graph.

Right now we have 2 problems:
  • 1. The tooltips only display for around 3/4 seconds. We tried the TooltipManager, shared instance and no luck there.
    2. The more serious one: Since we display the points on the graph and then connect the points with an XYLineRenderer the tooltips only appear when the user is precisely above the point. If it is anywhere in between it does not display anything. The idea is, if the mouse is hovering a point that does not have a tooltip we should display the same information as the nearest point to the left.
    Do you think this is possible?
Here is an image to better illustrate what we have right now
Image

Thanks !

colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

Re: Continuous tooltip

Post by colomb » Wed Jul 03, 2019 3:14 pm

1. Have you tried setting the dismiss delay, ChartPanel.setDismissDelay()?
2. If you search the board, you'll find some suggestions on finding the nearest point. Here is one version:

Code: Select all

    private ChartEntity findNearestEntity( ChartMouseEvent event )
    {
        ChartEntity entity = event.getEntity();

        if( ( Objects.isNull( entity ) || ( entity instanceof PlotEntity ) ) )
        {
            int x = ( int ) ( ( event.getTrigger().getX() - chartPanel.getInsets().left ) / chartPanel.getScaleX() );
            int y = ( int ) ( ( event.getTrigger().getY() - chartPanel.getInsets().top ) / chartPanel.getScaleY() );
            Point2D point2d = new Point2D.Double( x, y );
            double minDistance = Integer.MAX_VALUE;

            Collection entities = chartPanel.getChartRenderingInfo().getEntityCollection().getEntities();
            for( Object o : entities )
            {
                ChartEntity element = ( ChartEntity ) o;
                if( element instanceof XYItemEntity )
                {
                    Rectangle rect = element.getArea().getBounds();
                    Point2D centerPoint = new Point2D.Double( rect.getCenterX(), rect.getCenterY() );

                    if( point2d.distance( centerPoint ) < minDistance )
                    {
                        minDistance = point2d.distance( centerPoint );
                        entity = element;
                    }
                }
            }
        }

        return entity;
    }

Locked