I want to remove the straight line which is connecting the end points of the polar graph. It is not the part of dataset. I have also tried by inserting Double.NaN but results were not satisfiable, it created some extra connection to Double.Nan instead of breaking it.
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);
}
}
Use the DefaultPolarItemRenderer
method setConnectFirstAndLastPoint()
to alter the default behavior. Starting from the example examined here, the following change produces the chart shown below:
renderer.setConnectFirstAndLastPoint(false);