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

2

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?

Bacteriology answered 11/2, 2011 at 12:13 Comment(0)
B
40

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

LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
Bacteriology answered 11/2, 2011 at 14:6 Comment(0)
L
1

Here is the equivalent for older versions:

    StandardLegend legend = new StandardLegend();
    legend.setPreferredWidth(100);
    legend.setAnchor(Legend.EAST);
    jfreechart.setLegend(legend);
Lagerkvist answered 15/5, 2015 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.