Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the position and layout of a JFreeChart chart legend

Tags:

I am using JFreeChart to render a stacked area chart. By default, the chart legend is rendered below the plot with the elements laid out horizontally. I would like the legend to appear on the right of the plot with the elements laid out as a vertical list.

Is this possible and, if so, how do I do it?

like image 768
ireddick Avatar asked Feb 11 '11 12:02

ireddick


2 Answers

A little more time examining the API would have given me the answer:

LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
like image 150
ireddick Avatar answered Oct 18 '22 14:10

ireddick


Here is the equivalent for older versions:

    StandardLegend legend = new StandardLegend();
    legend.setPreferredWidth(100);
    legend.setAnchor(Legend.EAST);
    jfreechart.setLegend(legend);
like image 25
Vadzim Avatar answered Oct 18 '22 15:10

Vadzim