JFreeChart Get Legend Graphic

随声附和 提交于 2019-12-11 02:28:46

问题


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.

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.

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.


回答1:


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.

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());


来源:https://stackoverflow.com/questions/8302194/jfreechart-get-legend-graphic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!