Reputation: 91620
I'm creating graphs using JFreeChart:
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?
Upvotes: 1
Views: 888
Reputation: 196
I suggest using a second series with only one single value in it. For this second series you need to enable the drawing of shapes using the setSeriesShapesVisible() method of the plot renderer of the chart. All you need to do is adding one value to this second series in the point you want the shape to appear.
You can use squares, circles, rounded rectangle and some more. In fact any java.awt.Shape object is valid.
Upvotes: 0
Reputation: 205785
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));
Upvotes: 1