JFreeChart获取图例图形 [英] JFreeChart Get Legend Graphic

查看:134
本文介绍了JFreeChart获取图例图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在表格中以及通过双轴条形图/线JFreeChart显示数据.为了节省空间(将图表另存为PNG并与iText PDF一起放入PDF),我想从图例中获取图形,在表格视图中使用它们,然后删除图例.

In my application, I am showing data in a table as well as through a Dual Axis Bar/Line JFreeChart. To save some space (as the charts are being saved as PNG and put on PDF with iText PDF), I wanted to take the Graphics from the Legend, use them in the tabular view, and remove the legend.

是否可以获取图例项中的图标?我找到了 LegendGraphic 类,该类似乎是从 LegendItem 中检索图标的方法,但是在 LegendItem 表示确实如此.

Is there a way to grab the icons that lie with the legend item? I have found the LegendGraphic class, which seemed like would be the method to retrieve the icon from the LegendItem, but have not found anything in the documentation for LegendItem that would indicate it does.

最好将它们返回到可以轻松用于创建 com.itextpdf.text.Image 的对象中,例如 byte [] java.awt.Image .

It would be preferable if they were returned in an object that could easily be used to create a com.itextpdf.text.Image, such as byte[] or java.awt.Image.

推荐答案

您可以获取一系列文章'示例.另请参见 DefaultDrawingSupplier 详细了解 createStandardSeriesShapes() 有效.

You can get a series' LegendItem using the chart renderer's getLegendItem() method. You can change a series' Shape using the methods of ShapeUtilities, as shown in this example. See also DefaultDrawingSupplier for details of how createStandardSeriesShapes() works.

附录:请注意,即使您创建的图例没有图例或以后使用 chart.removeLegend(),渲染器的 getLegendItem()方法仍然有效.一旦有了 LegendItem ,就可以根据需要使用其属性.

Addendum: Note that the renderer's getLegendItem() method works even if you create the chart with no legend or later use chart.removeLegend(). Once you have the LegendItem, you can use it's attributes as required.

System.out.println(renderer.getLegendItem(0, 0).getShape());
System.out.println(renderer.getLegendItem(0, 0).getFillPaint());

这篇关于JFreeChart获取图例图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆