Hi All,
I've created my own class that extends ChartPanel and implements the ChartMouseListener. My class enables a user to click on an item in the graph, and a "window" is then displayed on the graph. The window displays more detailed information about the item the user clicked on. I have given the user the ability to move the window around the graph, however I would like to have a line drawn from my window to the clicked XYItemEntity.
Using XYItemEntity, I'm able to determin the X/Y Position of the item with respect to the graph axisii (sp?). However, in order for me to draw the line, I need to be able to determine the X/P Position of the item with responct to the Graphics object in paintComponent(Graphics g) method.
Does anyone know how I can do that? Or at least point me in the right direction?
Thanks!
Getting the (Graphics) X and Y Position for a XYItemEntity
-
- Posts: 13
- Joined: Thu May 18, 2006 6:01 pm
- Location: Washington DC
-
- Posts: 13
- Joined: Thu May 18, 2006 6:01 pm
- Location: Washington DC
Figured it out
Ok,.. I figured it out,..
in chartMouseClicked I had to do this:
If I didn't use translateJava2DToScreen it didn't do exactly what I needed it to,..
in chartMouseClicked I had to do this:
Code: Select all
translateJava2DToScreen(((ChartEntity)e.getEntity()).getArea().getBounds().getLocation()).getX();
translateJava2DToScreen(((ChartEntity)e.getEntity()).getArea().getBounds().getLocation()).getY();
If I didn't use translateJava2DToScreen it didn't do exactly what I needed it to,..
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Or perhaps you could use the ChartMouseEvent.getTrigger() method to get the original mouse event, and use the x, y coordinates of the mouse click.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 13
- Joined: Thu May 18, 2006 6:01 pm
- Location: Washington DC
Thanks!
I noticed that ChartMouseEvent.getTrigger() I could provide me with the mouse position. But, I really needed to know the position of the entity clicked, or at least a way to determine the position of a giving chart entity. This way, when a chart is zoomed in/out I could loop through my "custom windows" on the chartpanel, determine if the associated chart entity is displayed on the chart, then draw the custom window, and finnally draw a line from the custom window to the chart entity.
I hope that makes sense,.. anyway,.. it's working like a charm!
I hope that makes sense,.. anyway,.. it's working like a charm!