How to get the Y-Axis Value to use in XYLineAnnotation?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
williamt
Posts: 13
Joined: Thu Dec 14, 2006 1:22 pm

How to get the Y-Axis Value to use in XYLineAnnotation?

Post by williamt » Thu Mar 01, 2007 4:02 pm

Hi,
I am developing a chart application that needs to draw some lines in a plot (a fibonnaci series in a stock market chart tbh) based on the mousedrag start and finish points.
Right now, to draw the lines in the plot I'm using XYLineAnnotation, because I think it is the best way to keep the info on redrawing actions, such as zooming in or out the chart.
The drawing part is ok, I can draw the lines in the chart using XYLineAnnotation.
But there is two problems I am having troubles to solve:

- XYLineAnnotation uses 4 parameters: x1,y1,x2,y2, the coordinates of the start point and the end point of the line. But those coordinates are relative to the chart axis. How can I get those coords from a mouseclick/mousedrag event? I made a class that implements ChartMouseListener and added it to the ChartPanel object I'm using.

- How to get/handle mousedrag events on a chart/chartPanel? How to get that the user clicked in the graphic and not in the legend or something else?

Last but not least, if I have to change/create another type of Annotation to do that, can you give me tips about how should I do it?

Regards,
William

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

Re: How to get the Y-Axis Value to use in XYLineAnnotation?

Post by david.gilbert » Thu Mar 01, 2007 4:54 pm

williamt wrote:- XYLineAnnotation uses 4 parameters: x1,y1,x2,y2, the coordinates of the start point and the end point of the line. But those coordinates are relative to the chart axis. How can I get those coords from a mouseclick/mousedrag event?
Take a look at MouseListenerDemo4.java.
williamt wrote:- How to get/handle mousedrag events on a chart/chartPanel? How to get that the user clicked in the graphic and not in the legend or something else?
For mouse dragging, you are going to have to modify or subclass the ChartPanel class...there's currently nothing in the ChartMouseEvent mechanism for it.

To determine where the user clicked, you need to check the entities in the ChartRenderingInfo instance.
David Gilbert
JFreeChart Project Leader

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

williamt
Posts: 13
Joined: Thu Dec 14, 2006 1:22 pm

Post by williamt » Thu Mar 01, 2007 6:55 pm

Ok, I will check it!

Thanks!

When I get this working, I will post my results here.

Regards,
William

Locked