Question

I am using JFreeChart in Java to draw an XYLineChart containing 50+ x, y points. The chart is in a ChartPanel which is in 1 of the JPanels of my JFrame.

I know JFreeChart already has zoom functionality built-in whereby on a mouse click and drag, it zooms in/ out and displays the points under the selected "dragged" area.

I want to know if there is any way to have it return the x, y co-ordinates of the points if we zoom while pressing the CTRL, ALT or SHIFT key, i.e., if a user clicks a point on the chart and then drags the mouse, it should zoom as usual. But if the user clicks on a point and drags while pressing either SHIFT or ALT or CTRL keys, we should get a list of all the points selected on the Chart [the points underneath the dragged area]. Is this possible ? Kindly let me know how to go about it.

I did try to add a simple MouseListener to the ChartPanel to detect when the mouse is pressed & released but the x, y position values returned by the Mouse event correspond to the location of the Click on screen & not to the actual x, y co-ordinates of the points on the chart. I need the actual co-ordinates of all points that the user clicks and drags the mouse over, so as to calculate before which point was the mouse pressed and dragged & where the mouse was released and use that information to select multiple points underneath the dragged area.

If anyone has any idea about this, please let me know.

Était-ce utile?

La solution

This is the answer I gave in the JFreeChart forum:

It is not implemented in JFreeChart 1.0.17, but this feature has been implemented in the JFreeChart-FSE ("future state edition") project on GitHub:

https://github.com/jfree/jfreechart-fse

There has not been a release from this repo, but you can build it from the source. Feedback is welcome, I have not had time recently to work on this but I would like to get a release done from this repo some time in the coming months (my aim is to have JFreeChart 2.0 in 2014). The lasso selection came from some code that I wrote some years ago now, but Michael Zinsmaier from KNIME.org has done a big chunk of work to structure this and the dataset selection state.

Autres conseils

How do I get the actual plotted x, y values and not the x, y point on screen using the MouseListener?

Add a ChartMouseListener, as shown here and here.

Outside of JFreeChart, multiple selection with a lasso is illustrated in the example cited here. A marching ants rectangle is shown here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top