Jfreechart XYPlot,如何在绘图区域中绘制图例?
我正在我的应用程序中使用 XY 绘图绘制几个图表。 我可以在下面(或顶部、左侧或右侧)显示图例 情节。
但为了节省空间,我想在 XY 图中绘制一个图例框。
我能够将图像、文本和线条注释绘制到图中。
所以我尝试从我的 LegendTitle 中制作 TitleAnnotation 并添加此 情节的注释。
LegendTitle legend = new LegendTitle(plot.getRenderer());
XYTitleAnnotation anno = new XYTitleAnnotation(20.0, 40.0, legend);
plot.addAnnotation(anno);
注释的坐标(20.0, 40.0)位于绘图的可见区域中, 但什么也没画。
如果我让图表对象在图下绘制图例,这就很好了 (但不是我需要的)。
chart.addLegend(legend);
所以我认为 LegendTitle 对象是正确的。但为什么不画成Annotation呢?
我希望有人能解决这个问题,或者帮助我以不同的方式将图例绘制到绘图区域中。
i'm drawing several charts with XY-Plots in my application.
I have no problem displaying a legend under (or on top, left or right of)
the plot.
But to save space i want to draw a legend-box into the XY-Plot.
I'm able to draw image-,text- and line-annotations into the plot.
So i tried to make a TitleAnnotation from my LegendTitle and add this
annotation to the plot.
LegendTitle legend = new LegendTitle(plot.getRenderer());
XYTitleAnnotation anno = new XYTitleAnnotation(20.0, 40.0, legend);
plot.addAnnotation(anno);
The coordinates of the annotation(20.0, 40.0) are in the visible area of the plot,
but nothing is drawn.
If i let the Chart-Object draw the legend under the plot this is done fine
(but not what i need).
chart.addLegend(legend);
So i think the LegendTitle object is correct. But why is it not drawn as Annotation?
I hope someone can figure this out or help me with a different way to draw a legend into the plotarea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望它位于 XYPlot 内,我认为您需要一个
XYTextAnnotation
。If you want it to be inside an
XYPlot
, I think you need anXYTextAnnotation
.https://github.com/apetresc/JFreeChart
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html
http://kickjava.com/src/org/jfree/chart/DefaultOldLegend.java.htm
https://github.com/apetresc/JFreeChart
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html
http://kickjava.com/src/org/jfree/chart/DefaultOldLegend.java.htm