在 jfree 饼图中减少图例和图表之间的 space

Reduce space between legend and chart in jfree Pie chart

我把图例放在了左上角,图表和图例之间有一个不必要的空隙。 如何减少这个?

饼图与其边框之间有相当多的space。

public void setPie() {
    RingPlot plot = (RingPlot) this.chart.getPlot();

    plot.setSectionPaint("", WHITE_COLOR);
    plot.setCircular(true);
    plot.setShadowPaint(null);
}

public void setLegend() {
    LegendTitle legend = this.chart.getLegend();
    legend.setVerticalAlignment(VerticalAlignment.TOP);
    legend.setVisible(true);
    legend.setPosition(RectangleEdge.LEFT);

    Rectangle rect = new Rectangle(LEGEND_LENGTH, LEGEND_WIDTH);
    RingPlot plot = (RingPlot) this.chart.getPlot();
    plot.setLegendItemShape((Shape) rect);
}

您可以尝试调整 LegendTitle 周围的边距。类似于:

chart.getLegend().setMargin(top, left, bottom, right);

编辑:正如评论中 post 所建议的,您可以尝试在给定位置手动绘制图例:

//Print legend at X & Y location 
Rectangle2D r2DD = new Rectangle2D.Double(119, 47, 120, 180);
LegendTitle legend = new LegendTitle(chart.getPlot());
legendTitle.draw(g2,r2DD);

但我不确定如何实现它,因为您需要访问 ChartPanelGraphics2D。也许通过扩展 ChartPanel 和覆盖 paintComponent(Graphics g) ?