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

二次信任 提交于 2019-12-04 09:17:40

问题


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?


回答1:


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

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



回答2:


Here is the equivalent for older versions:

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


来源:https://stackoverflow.com/questions/4968852/how-to-specify-the-position-and-layout-of-a-jfreechart-chart-legend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!