Handling mouse events

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

Handling mouse events

Post by Dmitry Bessonov » Mon May 20, 2002 10:42 am

Hi, David!

Seems like there is no "mouse support" implemented in JFreeChart. Is it planned to be done in future?
And is there any way in 0.8.1. to get real data coordinates of point where user has clicked?


WBR,
Dmitry.

Mudit Wahal

Re: Handling mouse events

Post by Mudit Wahal » Tue May 21, 2002 3:42 pm

Extend JFreeChartPanel and add your own mouse support.

Thanks

Mudit

David Gilbert

Re: Handling mouse events

Post by David Gilbert » Tue May 21, 2002 7:55 pm

Hi Dmitry,

As Mudit suggests, JFreeChartPanel is the place to start. The panel is already listening for mouse clicks and handling them (in a limited way). There's a couple of things you should be aware of:

1) The chart/plot objects don't *retain* any information (size, location, whatever) about where they were last drawn. One chart can be drawn in multiple places (screen, printer, buffered image, PDF file etc,) at different sizes, so if it did retain size info you'd have to be sure you knew the last drawing was to the panel that you just clicked on.

2) The size and location information can be captured though, using a DrawInfo object (optionally passed to the chart's draw method, and populated as the chart is drawn...if you pass in null, no information is collected).

3) The JFreeChartPanel *does* retain the DrawInfo for the last chart drawing (in this.info). You can make use of this class to find out (for example) the area inside the chart's axes.

4) All ValueAxis subclasses have a method:

public double translateJava2DtoValue(float java2DValue, Rectangle2D plotArea);

The first argument is the coordinate of your mouse click, the second is the area inside the axes of your chart. This will convert mouse coordinates (Java2D) to values in your data range.

I hope this information is helpful. You will see some improvements in the mouse support in the next release of JFreeChart, and probably subsequent releases also.

Regards,

DG.

Locked