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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With