将图例嵌入JFreeChart的绘图区域

Jun*_*ter 7 jfreechart

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

LegendTitle legend=chart.getLegend();
legend.setPosition(RectangleEdge.TOP);
Run Code Online (Sandbox Code Playgroud)

Gra*_*amA 12

有一个如何设置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);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述