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
How to get the Y-Axis Value to use in XYLineAnnotation?
-
- 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?
Take a look at MouseListenerDemo4.java.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?
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.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?
To determine where the user clicked, you need to check the entities in the ChartRenderingInfo instance.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

