how to draw legend inside of a chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Hans Horn
Posts: 10
Joined: Mon Aug 04, 2008 10:39 pm

how to draw legend inside of a chart

Post by Hans Horn » Fri Oct 17, 2008 3:42 pm

Group,

I have not been able to figure out how draw a wrapped legend INSIDE of a chart's plot area such as

Code: Select all

------------------------------------------------------
|                                                                  
|                                                                  
|                                                                  
|    --------     
|   |o item1|    
|   |o item2|    
|   |o item3|    
|    --------     
|                                                                  
|                                                                  
|                                                                  
------------------------------------------------------
What do the experts think?
thx,
Hans

Hans Horn
Posts: 10
Joined: Mon Aug 04, 2008 10:39 pm

re: how to draw legend inside of a chart

Post by Hans Horn » Fri Oct 17, 2008 7:06 pm

I guess I found a solution:

- create chart with legend
- grab the legend, reconfigure it and place it as annotation onto the chart's plot
- remove the chart's legend

Code: Select all

...
LegendTitle legend = chart.getLegend(); 
legend.setPosition(RectangleEdge.RIGHT); // cause items to wrap
((XYPlot) chart.getPlot()).addAnnotation(new XYTitleAnnotation(0.25, 0.5, legend, RectangleAnchor.CENTER));
chart.removeLegend();
H.

Locked