Search code examples
jfreechart

Drawing annotation shapes without graph scaling


I'm creating graphs using JFreeChart:

enter image description here

The problem should be fairly clear. My circles which I'm drawing on the graph are showing up as ovals, since my graph is being scaled down to fit within my dimensions.

Here's how I'm drawing the circle annotations:

chart.getXYPlot().addAnnotation(
    new XYShapeAnnotation(
        new Ellipse2D.Float(pointX - 15, pointY - 15, 30, 30),
        new BasicStroke(0.5), Color.BLACK, Color.GREEN
    )
);

How can I draw an annotation without it being scaled down? Is there a way to draw on top of the graph, translating global/real X/Y points into local/scaled X/Y points?


Solution

  • As an alternative, try one of the scale-invariant annotations such as XYImageAnnotation or XYPointerAnnotation. For example,

    chart.getXYPlot().addAnnotation(
            new XYPointerAnnotation("Bam!", pointX, pointY, 0));