Jfreechart XYPlot,如何在绘图区域中绘制图例?

发布于 2024-12-04 01:30:29 字数 611 浏览 6 评论 0原文

我正在我的应用程序中使用 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 技术交流群。

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