Search code examples
javajfreechart

JFreeChart annotations not appearing


The following annotation - taken from the Developer's Guide - does not appear on a chart that I have created separately:

XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); 
annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); 
annotation.setRotationAngle(Math.PI / 4.0);
subplot1.addAnnotation(annotation);

The chart I have is a CombinedXYPlot. How do I go about troubleshooting why the annotation does not appear?

btw What are the units? i.e. 10000 is a pretty big number - what is mean by the "data space" for which these units pertain?


Solution

  • "Data space" means the range & domain space in which the data lives, which is defined by the min and max values of your axes.

    This annotation will be plotted at X=50 vs. Y=10000 vs. your chart's axes. Jfreechart then converts these coordinates into Swing coordinates (in pixels) to display the annotation properly.