3

我有一个包含许多部分的饼图,这个饼图的图例呈现为一行。如何将图例呈现为两列?

4

2 回答 2

9

在这里getLegendItem()看到的方法提供了在您选择的任何地方呈现图例项目所需的所有信息。将为任意数量的行将它们排列在两列中。要抑制现有图例,请在调用图表工厂时设置为;正如此处建议的那样,这些项目仍然可用。ContainerGridLayout(0, 2)legendfalse

附录:基于PieChartDemo1,此片段使用getLegendItems().iterator和 的变体ColorIcon

图例图像

public static JPanel createDemoPanel() {
    JPanel panel = new JPanel();
    JFreeChart chart = createChart(createDataset());
    panel.add(new ChartPanel(chart));
    panel.add(createLegendPanel((PiePlot) chart.getPlot()));
    return panel;
}

private static JPanel createLegendPanel(PiePlot plot) {
    JPanel panel = new JPanel(new GridLayout(0, 2, 5, 5));
    Iterator iterator = plot.getLegendItems().iterator();
    while (iterator.hasNext()) {
        LegendItem item = (LegendItem) iterator.next();
        JLabel label = new JLabel(item.getLabel());
        label.setIcon(new ColorIcon(8, item.getFillPaint()));
        panel.add(label);
    }
    return panel;
}
于 2012-11-09T14:07:14.250 回答
2

看看这个关于Legend Alignment的论坛主题,也在(网络档案)中。

看起来像你正在寻找的东西。如果没有,请发布更多信息或屏幕截图,说明您拥有什么以及您需要什么。

于 2012-11-09T13:28:38.213 回答