Great, but one more thing - Left Mouse on Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
H

Great, but one more thing - Left Mouse on Chart

Post by H » Fri Sep 09, 2005 5:44 pm

Hi,
Can anyone give an example to make the left mouse
button do something.
Rigth now, right mouse click start a menu - very useful.
Left mouse move can be used to show tooltips.

I would like to CLICK or PRESS left mouse button and
do something!


Thanks

H

christopher.loerken
Posts: 16
Joined: Wed Aug 31, 2005 4:25 pm

Post by christopher.loerken » Mon Sep 12, 2005 11:01 am

Add an own MouseListener to the chartpanel.

If you want for instance the x and y value of the clicked position you could try this:

Code: Select all

myChartPanel.addMouseListener(new MouseAdapter(){

            public void mouseClicked(java.awt.event.MouseEvent e) {    

                long xval = Math.round(chart.getXYPlot().getDomainAxis().java2DToValue(e.getX(),
                       getChartRenderingInfo().getPlotInfo().getDataArea(),
                       chart.getXYPlot().getDomainAxisEdge())); 
                long yval = Math.round(chart.getXYPlot().getRangeAxis().java2DToValue(e.getY(),
                       getChartRenderingInfo().getPlotInfo().getDataArea(),
                       chart.getXYPlot().getRangeAxisEdge())); 
                handleMouseClick(xval, yval);
            }
});

public void handleMouseClick(xval, yval){
     ....
}
Hope it helps,
christopher

Locked