Getting the (Graphics) X and Y Position for a XYItemEntity

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
the_schmitz
Posts: 13
Joined: Thu May 18, 2006 6:01 pm
Location: Washington DC

Getting the (Graphics) X and Y Position for a XYItemEntity

Post by the_schmitz » Wed Sep 06, 2006 2:57 pm

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!

the_schmitz
Posts: 13
Joined: Thu May 18, 2006 6:01 pm
Location: Washington DC

Figured it out

Post by the_schmitz » Thu Sep 07, 2006 12:44 am

Ok,.. I figured it out,..

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,..

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Sep 07, 2006 2:34 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

the_schmitz
Posts: 13
Joined: Thu May 18, 2006 6:01 pm
Location: Washington DC

Thanks!

Post by the_schmitz » Thu Sep 07, 2006 7:50 pm

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!

Locked