开发者

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

开发者 https://www.devze.com 2023-02-10 11:24 出处:网络
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

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 ver开发者_如何学编程tical list.

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


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

LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);


Here is the equivalent for older versions:

    StandardLegend legend = new StandardLegend();
    legend.setPreferredWidth(100);
    legend.setAnchor(Legend.EAST);
    jfreechart.setLegend(legend);
0

精彩评论

暂无评论...
验证码 换一张
取 消