20

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?

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
ireddick
  • 8,008
  • 2
  • 23
  • 21

2 Answers2

40

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

LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
ireddick
  • 8,008
  • 2
  • 23
  • 21
1

Here is the equivalent for older versions:

    StandardLegend legend = new StandardLegend();
    legend.setPreferredWidth(100);
    legend.setAnchor(Legend.EAST);
    jfreechart.setLegend(legend);
Vadzim
  • 24,954
  • 11
  • 143
  • 151