将图例嵌入JFreeChart的绘图区域

时间:2012-07-03 22:58:11

标签: jfreechart

JFreeChart中,是否可以将图例嵌入图表本身? 可以在图表的顶部,底部,左侧,右侧设置图例,如下所示,但是可以将其嵌入图表中吗?

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

1 个答案:

答案 0 :(得分:11)

有一个示例如何设置polt内的图例包含在JFreeChart Samples XYTitleAnnotationDemo1中,这是关键部分:

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

enter image description here