I am trying to create a sky plot in java using the jfreechart polar plot. Everything is working fine. However i was not able to change the various series legend markers and their size.
Here is an example for my code:
public class Skyplot {
private JFrame plotFrame = null;
public static void main (String[] args){
Skyplot sp = new Skyplot();
sp.display();
}
public Skyplot(){
}
public void display(){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
plot();
}
});
}
private void plot(){
// create and set up the window
plotFrame = new JFrame("Visualizer");
plotFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//Display the window.
plotFrame.pack();
plotFrame.setVisible(true);
plotFrame.setLocation(500, 500);
plotFrame.setSize(1200, 900);
// set up the content pane
Container C = plotFrame.getContentPane();
Plotter pl = new Plotter();
pl.setBorder(BorderFactory.createRaisedBevelBorder());
pl.setBackground(Color.WHITE);
C.setLayout(new GridLayout(1, 1));
C.add(pl);
}
private class Plotter extends JPanel {
private static final long serialVersionUID = 1L;
public Plotter(){
XYDataset dataset = getXYDataset();
final ChartPanel chartPanel = createChartPanel(dataset);
this.add(chartPanel, BorderLayout.CENTER);
}
private ChartPanel createChartPanel(XYDataset dataset) {
// Create chart
JFreeChart chart = ChartFactory.createPolarChart("Skyplot", dataset, true, true, false);
PolarPlot polPlot = (PolarPlot) chart.getPlot();
polPlot.setRadiusMinorGridlinesVisible(false);
polPlot.setBackgroundPaint(Color.WHITE);
polPlot.setRadiusGridlinePaint(Color.DARK_GRAY);
polPlot.setAngleGridlinePaint(Color.BLACK);
DefaultPolarItemRenderer renderer = (DefaultPolarItemRenderer) polPlot.getRenderer();
renderer.setBaseLegendShape(new Rectangle(15,15));
Font legend_font = new Font("Verdana", Font.PLAIN, 24);
renderer.setBaseLegendTextFont(legend_font);
NumberAxis rangeAxis = (NumberAxis) polPlot.getAxis();
rangeAxis.setTickUnit(new NumberTickUnit(10.0));
rangeAxis.setMinorTickMarksVisible(false);
rangeAxis.setRange(0.0, 90.0);
rangeAxis.setInverted(true);
return new ChartPanel(chart){
@Override
public Dimension getPreferredSize() {
double H = plotFrame.getHeight()*0.9;
double W = plotFrame.getWidth()*0.9;
return new Dimension((int)W, (int)H);
}
};
}
private XYDataset getXYDataset() {
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries g01= new XYSeries("G01");
series.add(35, 45);
dataset.addSeries(g01);
XYSeries g02= new XYSeries("G02");
series.add(105, 73);
dataset.addSeries(g01);
XYSeries g03= new XYSeries("G03");
series.add(264, 15);
dataset.addSeries(g03);
return dataset;
}
}
}
Any idea why would it not work? Am i doing something wrong with the Renderer? Any help would be appreciated. thank you.