views:

641

answers:

1

hi,

I'm having trouble understanding how the annotations system works. For example I can draw a vertical line as an annotation using some coordinates I get from the mouse, but I can't draw a line between 2 different points.

This works:

HighLowRenderer hlr=(HighLowRenderer)plot.getRenderer();

XYLineAnnotation a1=new XYLineAnnotation(chartX, 0, chartX, dataArea.getHeight(), bs1, Color.black);
hlr.addAnnotation(a1);

where chartX is a computed value from the mouse position.

This does not work:

HighLowRenderer hlr=(HighLowRenderer)plot.getRenderer();  
XYLineAnnotation a2=new XYLineAnnotation(175, 67, 230, 167, bs1, Color.black);
hlr.addAnnotation(a2);
+1  A: 

Take a look at this example, which adds XYLineAnnotations to the XYPlot object (in the above you're adding it to the renderer).

I had a lot of trouble with annotations, and unfortunately the only real advice I can offer is to look at the examples on http://www.java2s.com/

Brian Agnew