I can not manage to have annotation working on Multiple Axis Time Series
It works on primary Axis using plot.addAnnotation
but does not using renderer for secondary Axis
thank you for reading
TimeSeries Multiple Axis Annotation
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Annotations can be added to the entire plot, but can also be added to a specific renderer which will then be responsible for drawing (see XYItemRenderer.addAnotation(XYAnnotation annotation,Layer layer);
During drawing, the plot goes through all its renderers, gets for every rendererIndex a dataset with the same index, gets the axes by calling get[Domain/Range]AxisForDataset(i), and finally calls renderer.drawAnnotations(...).
Annotations assigned to the plot are called after the renderer-specific annotations.
During drawing, the plot goes through all its renderers, gets for every rendererIndex a dataset with the same index, gets the axes by calling get[Domain/Range]AxisForDataset(i), and finally calls renderer.drawAnnotations(...).
Annotations assigned to the plot are called after the renderer-specific annotations.
annotation
here is my code
annotation is ok on first dataset but nothing on 2nd dataset
/************/
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset).getStartY(0,50).doubleValue(),
11, 11, cd);
xyplot.addAnnotation(bestBid);
final XYPointerAnnotation pointer =
new XYPointerAnnotation("Series 1 Annotation",
((TimeSeriesCollection)xydataset).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer.setBaseRadius(35.0);
pointer.setTipRadius(10.0);
pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer.setPaint(Color.blue);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
xyplot.addAnnotation(pointer);
/************/
final CircleDrawer cd2 = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid2 = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
11, 11, cd2);
//standardxyitemrenderer2.addAnnotation(bestBid2);
(xyplot.getRenderer(1)).addAnnotation(bestBid2);
final XYPointerAnnotation pointer2 =
new XYPointerAnnotation("Series 2 Annotation",
((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer2.setBaseRadius(35.0);
pointer2.setTipRadius(10.0);
pointer2.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer2.setPaint(Color.blue);
pointer2.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
standardxyitemrenderer2.addAnnotation(pointer2);
thank u for ur help
annotation is ok on first dataset but nothing on 2nd dataset
/************/
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset).getStartY(0,50).doubleValue(),
11, 11, cd);
xyplot.addAnnotation(bestBid);
final XYPointerAnnotation pointer =
new XYPointerAnnotation("Series 1 Annotation",
((TimeSeriesCollection)xydataset).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer.setBaseRadius(35.0);
pointer.setTipRadius(10.0);
pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer.setPaint(Color.blue);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
xyplot.addAnnotation(pointer);
/************/
final CircleDrawer cd2 = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid2 = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
11, 11, cd2);
//standardxyitemrenderer2.addAnnotation(bestBid2);
(xyplot.getRenderer(1)).addAnnotation(bestBid2);
final XYPointerAnnotation pointer2 =
new XYPointerAnnotation("Series 2 Annotation",
((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer2.setBaseRadius(35.0);
pointer2.setTipRadius(10.0);
pointer2.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer2.setPaint(Color.blue);
pointer2.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
standardxyitemrenderer2.addAnnotation(pointer2);
thank u for ur help

annotations - found a fix
This one works fine !!!!
using 2 as index for 2nd renderer .........
though 0 would be the index to the 1st renderer and 1 to the 2nd
did I miss something
pat
/************/
final CircleDrawer cd2 = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid2 = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
11, 11, cd2);
//standardxyitemrenderer2.addAnnotation(bestBid2);
(xyplot.getRenderer(2)).addAnnotation(bestBid2,Layer.FOREGROUND);
final XYPointerAnnotation pointer2 =
new XYPointerAnnotation("Series 2 Annotation",
((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer2.setBaseRadius(35.0);
pointer2.setTipRadius(10.0);
pointer2.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer2.setPaint(Color.blue);
pointer2.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
(xyplot.getRenderer(2)).addAnnotation(pointer2,Layer.FOREGROUND);

using 2 as index for 2nd renderer .........
though 0 would be the index to the 1st renderer and 1 to the 2nd
did I miss something
pat
/************/
final CircleDrawer cd2 = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid2 = new XYDrawableAnnotation(((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
11, 11, cd2);
//standardxyitemrenderer2.addAnnotation(bestBid2);
(xyplot.getRenderer(2)).addAnnotation(bestBid2,Layer.FOREGROUND);
final XYPointerAnnotation pointer2 =
new XYPointerAnnotation("Series 2 Annotation",
((TimeSeriesCollection)xydataset2).getStartX(0,50).doubleValue(),
((TimeSeriesCollection)xydataset2).getStartY(0,50).doubleValue(),
3.0 * Math.PI / 4.0);
pointer2.setBaseRadius(35.0);
pointer2.setTipRadius(10.0);
pointer2.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer2.setPaint(Color.blue);
pointer2.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
(xyplot.getRenderer(2)).addAnnotation(pointer2,Layer.FOREGROUND);


annotation
simple bug in my prg
found it and everything works fine !!!
found it and everything works fine !!!
annotation - final code
public static void testAddAnnotation( String text,
XYPlot plot ,
TimeSeriesCollection ds,
Color color,
int rindex, int index )
{
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid = new XYDrawableAnnotation(ds.getStartX(0,index).doubleValue(),
ds.getStartY(0,index).doubleValue(),
11, 11, cd);
(plot.getRenderer(rindex)).addAnnotation(bestBid,Layer.FOREGROUND);
final XYPointerAnnotation pointer =
new XYPointerAnnotation(text,
ds.getStartX(0,index).doubleValue(),
ds.getStartY(0,index).doubleValue(),
3.0 * Math.PI / 4.0);
pointer.setBaseRadius(35.0);
pointer.setTipRadius(10.0);
pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer.setPaint(color);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
(plot.getRenderer(rindex)).addAnnotation(pointer,Layer.FOREGROUND);
}
e.g
testAddAnnotation( "Series 1 Annotation", xyplot , (TimeSeriesCollection)xydataset, Color.black,0, 50 );
testAddAnnotation( "Series 2 Annotation", xyplot , (TimeSeriesCollection)xydataset1, Color.red, 1, 50 );
testAddAnnotation( "Series 3 Annotation", xyplot , (TimeSeriesCollection)xydataset2, Color.blue , 2, 50 );
testAddAnnotation( "Series 4 Annotation", xyplot , (TimeSeriesCollection)xydataset3 , Color.green, 3, 50 );
XYPlot plot ,
TimeSeriesCollection ds,
Color color,
int rindex, int index )
{
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null);
final XYAnnotation bestBid = new XYDrawableAnnotation(ds.getStartX(0,index).doubleValue(),
ds.getStartY(0,index).doubleValue(),
11, 11, cd);
(plot.getRenderer(rindex)).addAnnotation(bestBid,Layer.FOREGROUND);
final XYPointerAnnotation pointer =
new XYPointerAnnotation(text,
ds.getStartX(0,index).doubleValue(),
ds.getStartY(0,index).doubleValue(),
3.0 * Math.PI / 4.0);
pointer.setBaseRadius(35.0);
pointer.setTipRadius(10.0);
pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
pointer.setPaint(color);
pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT);
(plot.getRenderer(rindex)).addAnnotation(pointer,Layer.FOREGROUND);
}
e.g
testAddAnnotation( "Series 1 Annotation", xyplot , (TimeSeriesCollection)xydataset, Color.black,0, 50 );
testAddAnnotation( "Series 2 Annotation", xyplot , (TimeSeriesCollection)xydataset1, Color.red, 1, 50 );
testAddAnnotation( "Series 3 Annotation", xyplot , (TimeSeriesCollection)xydataset2, Color.blue , 2, 50 );
testAddAnnotation( "Series 4 Annotation", xyplot , (TimeSeriesCollection)xydataset3 , Color.green, 3, 50 );
Re: TimeSeries Multiple Axis Annotation
Thank you so much boulayp.....It was of great help....