How to create rectangular selection?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
geojohn
Posts: 2
Joined: Fri May 16, 2008 3:45 am

How to create rectangular selection?

Post by geojohn » Fri May 16, 2008 3:51 am

I have a requirement for creating a rectangular selection area for scatter charts. Also i need to find out the scatter chart points that comes under the selected area.

jpmaia
Posts: 53
Joined: Fri Feb 22, 2008 10:44 pm

Post by jpmaia » Fri May 16, 2008 7:32 pm

I implemented this. I posted the basic details in the following thread in this forum:
http://www.jfree.org/phpBB2/viewtopic.php?t=24320

The above thread provides just the basic details on the approach to take.

Before you ask, it is too difficult for me to move my code from my non-internet-access work PC to a PC where I could post it here. Besides, I'd have to do quite a bit of massaging in order to provide a minimal-code demo to post.

geojohn
Posts: 2
Joined: Fri May 16, 2008 3:45 am

Post by geojohn » Mon May 19, 2008 11:51 am

Can you please give the code snippet for finding whether the points inside the rectangular selection?
Just a few lines is enough, not the entire code.
Thanks in Advance,
Geo

jpmaia
Posts: 53
Joined: Fri Feb 22, 2008 10:44 pm

Post by jpmaia » Mon May 19, 2008 11:16 pm

It is a bit more involved than just a few lines.

Essentially, you do the following:
- get the chart rendering info from the panel.
- get the entity collection from the rendering info.
- loop through the entity collection and for the XYItemEntity-s you
compare their chart position with the saved rectangle for the
selection area. The 'outcode' method for the rectangle area
should be used to see if the x/y location of the item entities
are within the rectangle (a value of 0 indicates it is).
- you now have the list of items within the selection area.
- you will have to map these item entities to any data associated
with your chart points since these entities provide strictly chart
plotting info. You can get the series index and item index from
these entities. I used these indexes to reference data I saved
external to JFreeChart.

Locked