java 如何删除jfree极坐标图中端点之间的连接/线?

yruzcnhs  于 2023-04-10  发布在  Java
关注(0)|答案(1)|浏览(153)

我想删除连接极图端点的直线。它不是数据集的一部分。我也尝试插入Double.NaN,但结果不满意,它创建了一些额外的连接到Double.Nan,而不是断开它。

public class PolarPanel extends JPanel {
private static final long serialVersionUID = 1L;
XYSeriesCollection dataset;

public PolarPanel() {
    setLayout(new BorderLayout());
    dataset = new XYSeriesCollection();
    add(new JLabel("No Data Available", JLabel.CENTER), BorderLayout.CENTER);
}

public void setGraph(XYSeries polarseries) {
    dataset.removeAllSeries();
    dataset.addSeries(polarseries);
    JFreeChart chart = ChartFactory.createPolarChart("Polar", dataset, isBackgroundSet(),
            getIgnoreRepaint(),getFocusTraversalKeysEnabled());
    PolarPlot plot = (PolarPlot) chart.getPlot();

    var renderer = new DefaultPolarItemRenderer();
    renderer.setShapesVisible(false);
    NumberAxis xAxis = (NumberAxis) plot.getAxis();
    xAxis.setTickUnit(new NumberTickUnit(10));

    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.WHITE);

    plot.setAngleGridlinesVisible(true);
    plot.setAngleGridlinePaint(Color.BLACK);

    plot.setRadiusGridlinesVisible(true);
    plot.setRadiusGridlinePaint(Color.BLACK);

    chart.getLegend().setFrame(BlockBorder.NONE);

    chart.setTitle(new TextTitle("Polar", new Font("Serif", java.awt.Font.BOLD, 18)));
    chart.removeLegend();
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    chartPanel.setBackground(Color.WHITE);
    BorderLayout layout = (BorderLayout) this.getLayout();
    if(layout.getLayoutComponent(BorderLayout.CENTER)!=null)
        this.remove(layout.getLayoutComponent(BorderLayout.CENTER));
    this.add(chartPanel, BorderLayout.CENTER);
}

}

3htmauhk

3htmauhk1#

使用DefaultPolarItemRenderer方法setConnectFirstAndLastPoint()来改变默认行为。从here示例开始,以下更改将生成如下所示的图表:

renderer.setConnectFirstAndLastPoint(false);

相关问题