Embed the legend into the plot area of JFreeChart

岁酱吖の 提交于 2019-12-18 05:57:48

问题


In JFreeChart, is it possible to embed the legend into the chart itself? Legend can be set on top, bottom, left, right of the chart as follows, but is it possible to imbed it into the chart?

LegendTitle legend=chart.getLegend();
legend.setPosition(RectangleEdge.TOP);

回答1:


There is an example of how to set the legend inside the polt are included in the JFreeChart Samples XYTitleAnnotationDemo1, this is the key part:

XYPlot plot = (XYPlot) chart.getPlot();
LegendTitle lt = new LegendTitle(plot);
lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
lt.setBackgroundPaint(new Color(200, 200, 255, 100));
lt.setFrame(new BlockBorder(Color.white));
lt.setPosition(RectangleEdge.BOTTOM);
XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt,RectangleAnchor.BOTTOM_RIGHT);

ta.setMaxWidth(0.48);
plot.addAnnotation(ta);



来源:https://stackoverflow.com/questions/11320360/embed-the-legend-into-the-plot-area-of-jfreechart

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