使用 JFreeChart 在线图上注释点?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难说为什么您的 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.