Tooltip only shows after first click [SOLVED]

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Alfred63
Posts: 22
Joined: Mon Jun 21, 2004 9:38 pm

Tooltip only shows after first click [SOLVED]

Post by Alfred63 » Tue Jul 11, 2006 4:16 pm

I'm finding that my tooltips are not showing until after I right click (show popup menu) and then dismiss the menu. After that the tooltips work as expected. Is this a known problem?

Why would showing the chartpanel popup menu activate tooltip help?

Here are some details:

jfreechart-1.0.1.jar
jcommon-1.0.0.jar
jre 1.5.0_07-b03

Code: Select all

abstract class AbstractMopChart extends JPanel implements DataManager2Listener
{
    private TimeSeries avgSeries;
    private TimeSeries minSeries;
    private TimeSeries maxSeries;
    ChartPanel chartPanel;
    JFreeChart chart;
            
    AbstractMopChart ()
    {
        super (new BorderLayout ());
        
        setBackground (MopMainPanel.MopPanelColor);

        avgSeries = new TimeSeries ("Avg", Hour.class);
        minSeries = new TimeSeries ("Min", Hour.class);
        maxSeries = new TimeSeries ("Max", Hour.class);
      
        TimeSeriesCollection dataset = new TimeSeriesCollection (avgSeries);
        dataset.addSeries (minSeries);
        dataset.addSeries (maxSeries);
        
        DateAxis domain = new DateAxis ("Time");
        
        domain.setTickLabelFont (new Font ("SansSerif", Font.PLAIN, 10));
        domain.setLabelFont (new Font ("SansSerif", Font.PLAIN, 12));
        
        StandardXYItemRenderer renderer = new StandardXYItemRenderer (StandardXYItemRenderer.LINES);
        
        renderer.setSeriesPaint (0, Color.GREEN);
        renderer.setSeriesPaint (1, Color.BLUE);
        renderer.setSeriesPaint (2, Color.RED);
        
        XYToolTipGenerator generator = new StandardXYToolTipGenerator (
                "Value={2} on {1}", 
                new SimpleDateFormat ("MMM-d-yyyy"),
                new DecimalFormat ("0.00"));
        renderer.setToolTipGenerator (generator);
        
        renderer.setStroke(new BasicStroke(2f, 
                BasicStroke.CAP_BUTT, 
                BasicStroke.JOIN_BEVEL));
        
        ValueAxis range = createRangeAxis();
        
        XYPlot plot = new XYPlot(dataset, domain, range, renderer);
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        plot.setForegroundAlpha(0.8f);
        
        
        domain.setAutoRange(true);
        domain.setLowerMargin(0.0);
        domain.setUpperMargin(0.0);
        domain.setTickLabelsVisible(true);
        chart = new JFreeChart("Generic",
                new Font("SansSerif", Font.BOLD, 14),
                plot,
                true);
        chart.setBackgroundPaint(Color.white);
        chartPanel = new ChartPanel(chart);
        
    }
    
    public ValueAxis createRangeAxis ()
    {
        LogarithmicAxis range = new LogarithmicAxis ("Value");
        range.setAllowNegativesFlag (true);
        range.setAutoRangeNextLogFlag (true);
        range.setStrictValuesFlag (false);
        range.setTickLabelFont (new Font("SansSerif", Font.PLAIN, 10));
        range.setLabelFont (new Font ("SansSerif", Font.PLAIN, 12));
        range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        return (range);
    }
    
    public void clearSeries ()
    {
        if ((avgSeries != null) &&
            (avgSeries.getItemCount () > 0))
        {
            avgSeries.clear ();
        }
        
        if ((minSeries != null) &&
            (minSeries.getItemCount () > 0))
        {
            minSeries.clear ();
        }
        
        if ((maxSeries != null) &&
            (maxSeries.getItemCount () > 0))
        {
            maxSeries.clear ();
        }
    }

    public void addAvgMinMax (Class granularity, Date time, Number avg, Number min, Number max)
    {   
        try
        {
            RegularTimePeriod t = RegularTimePeriod.createInstance (granularity,
                        time,
                        TimeZone.getDefault ());
            avgSeries.add (t, avg);
            minSeries.add (t, min);
            maxSeries.add (t, max);
        } 
        catch (Exception e)
        {
            e.printStackTrace ();
        }
    }

    public void dataError(DataManager2Event dataEvent)
    {
    }

    public void dataRead(DataManager2Event dataEvent)
    {
        if (dataEvent.getData() != null)
        {
            if (dataEvent.getData() instanceof ArrayList)
            {
                clearSeries ();
                
                ArrayList <ArrayList> data = (ArrayList) dataEvent.getData ();
                for (ArrayList r : data)
                {
                    addAvgMinMax (Hour.class,
                            (Date)r.get (0), 
                            (Number)r.get (1),
                            (Number)r.get (2),
                            (Number)r.get (3));
                }
            }
        }
    }
    
    public void dataWritten(DataManager2Event dataEvent)
    {
    }
}

-Dennis
Last edited by Alfred63 on Tue Jul 11, 2006 7:17 pm, edited 1 time in total.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Tue Jul 11, 2006 4:25 pm

Perhaps the frame containing the chartPanel needs to have the focus. Try calling

Code: Select all

chartPanel.requestFocusInWindow();

Alfred63
Posts: 22
Joined: Mon Jun 21, 2004 9:38 pm

Post by Alfred63 » Tue Jul 11, 2006 4:54 pm

skunk wrote:Perhaps the frame containing the chartPanel needs to have the focus. Try calling

Code: Select all

chartPanel.requestFocusInWindow();
Thanks!

You've helped me focus in on the problem (oh the pun) but that doesn't seem to fix it. I'm running this inside of a web browser and it seems that I must click within the applet area, doesn't have to be on the chart components, and then the tooltips will show.

This is not related to the new microsoft click to activate applet changes. I'm actually running this inside of netscape 8.1 and firefox 1.5.

Getting back to your fix. I placed your code, near the end of my datamanager listener - dataRead (). This method is called when new data is available for charting.

This did not fix the problem but I am now curious whether the click once behaviour is standard for applets?


-Dennis

Alfred63
Posts: 22
Joined: Mon Jun 21, 2004 9:38 pm

[Solved]

Post by Alfred63 » Tue Jul 11, 2006 7:16 pm

Turned out to be a totally different problem. An exception was causing this side effect.

Thanks again for your help.

-Dennis

Locked