Drawing annotation shapes without graph scaling

岁酱吖の 提交于 2020-01-21 19:53:26

问题


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?


回答1:


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));



回答2:


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.



来源:https://stackoverflow.com/questions/12919424/drawing-annotation-shapes-without-graph-scaling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!