Insert Legend into JFreeChart Story Area

In JFreeChart , is it possible to insert a legend into the chart itself? A legend can be installed at the top, bottom, left, right of the chart as follows, but can it be inserted into the chart?

 LegendTitle legend=chart.getLegend(); legend.setPosition(RectangleEdge.TOP); 
+7
source share
1 answer

Here is an example of how to set the legend inside polt, included in 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); 

enter image description here

+11
source

All Articles