【发布时间】:2019-02-06 10:04:04
【问题描述】:
我正在使用 Swing 和 JFreeChart 制作一个小应用程序。我必须显示一个XYLineChart,我想在它上面画一些填充的矩形。我使用XYShapeAnnotation 绘制矩形,并尝试用Graphics2D 填充它们,但它不起作用。我得到了显示在图表上的矩形,但没有填充。代码如下所示:
Shape rectangle = new Rectangle2D.Double(0, 0, 7, 1);
g2.fill(rectangle);
XYShapeAnnotation shapeAnnotation = new XYShapeAnnotation(rectangle, new BasicStroke(2.f), Color.BLACK);
shapeAnnotation.setToolTipText("1");
plot.addAnnotation(shapeAnnotation);
我认为问题在于填充的矩形位置与图表无关,但我真的不知道如何解决这个问题。我还想知道是否可以在图表中的矩形上方显示线条,因为我没有找到任何方法。
【问题讨论】:
标签: java swing jfreechart