Annotations in General

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Klyde100
Posts: 5
Joined: Tue Feb 16, 2010 9:40 pm
antibot: No, of course not.

Annotations in General

Post by Klyde100 » Fri Dec 09, 2011 8:38 pm

I've read the other postings and I thought I followed the use of them, but I cannot seem to make
Annotations visible. I was to show an average for my line plots on a CombinedDomainXYPlot for each plot.
Do I need to somehow add more space to the end of the lines so that the Annotation will appear?
If that is what I am missing I am not sure how to add it.

As I add my subplots in a loop I add the Annotation to each :
final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 100.0);
annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));

--Loop is here
XYPlot subplot1 = new XYPlot (dataset, null, rangeAxis, renderer1);
subplot.addAnnotation(annotation);
plot.add(subplot1);

--end loop
chart = new JFreeChart(
"Comparison Chart",
new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12),
plot,
true);

Klyde100
Posts: 5
Joined: Tue Feb 16, 2010 9:40 pm
antibot: No, of course not.

Re: Annotations in General

Post by Klyde100 » Mon Dec 12, 2011 5:51 pm

Not sure if this is just a dumb question, or it's just not that interesting.

For the call: final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, y);
Are the x and y params supposed to be related to the data values, or are they
x-y coordinates of the plot? I've tried a number of different values, still cannot seem to
see anything. Am I missing something here? Is there a better way to put a line's average value
at the end of it? This annotation in theory seemed the best way. I'm stuck. :mrgreen:

mkrauskopf
Posts: 31
Joined: Thu May 27, 2010 4:23 pm
antibot: No, of course not.

Re: Annotations in General

Post by mkrauskopf » Mon Dec 12, 2011 10:43 pm

Javadoc for XYTextAnnotation ctor clearly states:

Code: Select all

  x - the x-coordinate (in data space)
  y - the y-coordinate (in data space)
So if the ranges or your (sub)plot are let's say domain = <0, 100>; range = <1000, 2000> then x and y for the annotation have to fall within the ranges, e.g. x = 50, y = 1200. Otherwise annotation will not be visible. That's how I understand it and how it does work for me. May be if you can come with complete minimalistic example which does not work for you, it would help to solve the issue.

Cheers,
-- m.

Klyde100
Posts: 5
Joined: Tue Feb 16, 2010 9:40 pm
antibot: No, of course not.

Re: Annotations in General

Post by Klyde100 » Wed Dec 14, 2011 7:31 pm

M,

Thanks for answering. I tried that too. My chart y values range from 0->10000, x is time based, and range
between 00:00 to 01:20. So one of my Annotation tests is defined like this:

SimpleDateFormat dfm = new SimpleDateFormat(timeBasis);
Date a = dfm.parse("00.00");
t = a.getTime();

annotation = new XYTextAnnotation("Hello!", t, 9500);

But it still does not appear. What am I missing here? I am assuming that the y value just needs to be within the
range of possible y values, not an exact value. Correct?

Klyde100
Posts: 5
Joined: Tue Feb 16, 2010 9:40 pm
antibot: No, of course not.

Re: Annotations in General

Post by Klyde100 » Wed Dec 14, 2011 9:08 pm

Just in case anyone else has this problem, I thought I'd explain what I did wrong, as I got it working now.

M was kinda correct. The issue was the format of the values on the x-axis, not exactly their value.
My graph was being drawn using 'double' for the time but I was using the format as it appears on the x axis,
a time value. When I converted the time values back to doubles the Annotations appeared.

So, the x and y values need to be in the proper format and within the range of data. Seems pretty obvious
now :cry:

Locked