XYPointerAnnotation not primary dataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

XYPointerAnnotation not primary dataset

Post by pdvmipv » Mon May 11, 2009 1:34 pm

Hi

i have a problem to add an annotation relative to a dataset that isn't the primary.
Imagine a xy plot where I plot, for example, two datasets with the same x axis and two different y axis.
Then I want to draw an annotation for the two different dataset.

When I click with the mouse on the plot of the first (primary) dataset, i retrieve the information of where i have to add the annotation, and then I draw correctly the annotation on the chart.

Then I want to add the annotation for the second dataset.
I click with the mouse on the plot of the second dataset, I retrieve the information of where i have to add the annotation,
and then when I draw the annotation nothing appears. This because the annotaion function always works with
coordinates respect to the main axis. So now the question is: How can I switch coordinates in order to allow to the second
annotion call to display the annotation for the second dataset on the chart ...or What is the calling sequence to
allow the drwaing of the annotation for the second or further datasets ?

Thanks

mkivinie
Posts: 51
Joined: Wed Jul 06, 2005 8:35 am

Re: XYPointerAnnotation not primary dataset

Post by mkivinie » Mon May 11, 2009 2:15 pm

Instead of adding the Annotation to the XYPlot add it to the renderer responsible for your second dataset.

Similarly you could add the Annotations for the first dataset to its renderer instead of the XYPlot.
See:

Code: Select all

XYItemRenderer.addAnnotation(XYAnnotation annotation) 

pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

Re: XYPointerAnnotation not primary dataset

Post by pdvmipv » Mon May 11, 2009 3:11 pm

Ok, it works prerfectly,
thanks

but now i can't retrieve the list of annotation added to the renderer,
becuase from XYPlot.getRenderer.getAnnotations() doesn't exist a function similar to XYPlot.getAnnotations()

Are there any method to give this informations?

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

Re: XYPointerAnnotation not primary dataset

Post by paradoxoff » Tue May 12, 2009 8:47 am

pdvmipv wrote: Are there any method to give this informations?
Yes. Check AbstractXYItemRenderer.getAnnotations(). Unfortunately the method is not part of the XYItemRenderer interface. In order to use the method, you will have to cast the XYItemRenderer returned from XYPlot.getRenderer() to an AbstractXYItemRenderer.

pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

Re: XYPointerAnnotation not primary dataset

Post by pdvmipv » Tue May 12, 2009 10:11 am

Ok, perfect!

Thanks

Locked