使用 JFreeChart 在线图上注释点?

发布于 2024-11-28 05:20:48 字数 804 浏览 2 评论 0原文

我正在使用 JFreeChart 制作折线图。我想用不同大小的圆圈来标记或注释一些点。我尝试了 ShapeAnnotation,但即使在 addAnnotation 之后,它也不可见。不过,我能够进行指针注释。 这是相关的代码:

 XYShapeAnnotation annotation = new XYShapeAnnotation(new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f), new BasicStroke(1.0f), Color.blue);
XYPointerAnnotation pointer = new XYPointerAnnotation("arrow", 0.5,0.5,0.0);
xyDataset.addSeries(series1); //
xyDataset.addSeries(series2); // random lists of numbers
xyDataset.addSeries(series3); //
JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart","Age","Weight",xyDataset,PlotOrientation.VERTICAL,true,true,false);
chart.getXYPlot().addAnnotation(pointer);
chart.getXYPlot().addAnnotation(annotation);

我认为我应该有更多的代码来使椭圆注释可见,因为我从未像使用指针那样指定坐标。我浏览了 JFreeChart API 但找不到它。帮助?

I'm using JFreeChart to make a line graph. There are some points that I want to mark, or annotate, with circles of different sizes. I tried ShapeAnnotation, but even after I addAnnotation, it's not visible. I was able to make a pointer annotation, though.
Here's the relevant code:

 XYShapeAnnotation annotation = new XYShapeAnnotation(new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f), new BasicStroke(1.0f), Color.blue);
XYPointerAnnotation pointer = new XYPointerAnnotation("arrow", 0.5,0.5,0.0);
xyDataset.addSeries(series1); //
xyDataset.addSeries(series2); // random lists of numbers
xyDataset.addSeries(series3); //
JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart","Age","Weight",xyDataset,PlotOrientation.VERTICAL,true,true,false);
chart.getXYPlot().addAnnotation(pointer);
chart.getXYPlot().addAnnotation(annotation);

I think I should have more code to make the ellipse annotation visible because I never specified coordinates like I did with the pointer. I went through the JFreeChart API and couldn't find it. Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2024-12-05 05:20:48

很难说为什么您的 XYShapeAnnotation 会在没有看到您的数据的情况下失败; sscce 会有所帮助。作为起点,您可以查看此处的示例和<一个href="https://stackoverflow.com/questions/6797012/jfreechart-series-tool-tip-above-shape-annotation/6802375#6802375">此处进行比较。

It's hard to say why your XYShapeAnnotation fails without seeing your data; an sscce would help. As a starting point, you might look at the examples here and here for comparison.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文