How to create rectangular selection?
How to create rectangular selection?
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.
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.
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.
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.
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.