TimeSeries Multiple Axis Annotation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

TimeSeries Multiple Axis Annotation

Post by boulayp » Thu Jan 15, 2009 7:36 pm

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

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Post by paradoxoff » Fri Jan 16, 2009 8:17 am

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.

boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

annotation

Post by boulayp » Sat Jan 17, 2009 9:27 am

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 8)

boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

annotations - found a fix

Post by boulayp » Sat Jan 17, 2009 9:42 am

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);

:D :D

boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

annotation

Post by boulayp » Sat Jan 17, 2009 9:47 am

simple bug in my prg
found it and everything works fine !!!

boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

annotation - final code

Post by boulayp » Sat Jan 17, 2009 10:48 am

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 );

boulayp
Posts: 7
Joined: Thu Jan 15, 2009 7:29 pm

Post by boulayp » Sat Jan 17, 2009 11:21 am

Image

Buddy
Posts: 5
Joined: Fri Apr 24, 2009 7:54 am

Re: TimeSeries Multiple Axis Annotation

Post by Buddy » Tue May 05, 2009 6:41 am

Thank you so much boulayp.....It was of great help....

Locked