Polar Chart

In this section we are providing you an example to create a Polar Chart.

Polar Chart

Polar Chart

     

In this section we are providing you an example to create a Polar Chart.

Description of Program

For creating a Polar Chart we use the object of XYDataset. Before creating the object of XYDataset we have to create the objects of XYSeries for representing the data. We add the data in this series by add() method. And then we add this series to XYSeriesCollection by addSeries() method. XYSeriesCollection object represent the collection of XYSeries objects, which is used as a dataset.

Description of code

Firstly we have to create the object of XYSeries that is used to represent the data items.
  XYSeries s1=new XYSeries("a");

And then we add the data in the series by add() method.
  s1.add(20,5);
  s1.add(213,7);

After creating the data series we have to create the object of XYSeriesCollection object that is used to represent the collection of XYSeries objects, which is used as a dataset.

  JFreeChart chart = ChartFactory.createPolarChart("Polar Chart", dataset, true, true, false);
After added the data in dataset we create the Polar Chart by invoking the createPolarChart() method. This method is a static method of ChartFactory class and its returns the object of JFreeChart type. This method syntax is:
  Public static JFreeChart createPolarChart(java.lang.String title, XYDataset dataset, boolean legend, boolean tooltips, boolean urls);

  ChartFrame frame1=new ChartFrame(?Polar Chart",chart);
After this we create the object of ChartFrame. It is used to display a chart.

Here is a code of the Program :

import java.awt.*;
import org.jfree.data.xy.*;
import org.jfree.chart.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;

public class PolarDemo{
  public static void main(String args[]){
  XYSeries s1=new XYSeries("a");
  s1.add(20,5);
  s1.add(213,7);
  s1.add(160,2);
  XYSeries s2=new XYSeries("b");
  s2.add(360,2);
  s2.add(200,7);
  s2.add(145,5);
  XYSeries s3=new XYSeries("c");
  s3.add(225,9);
  s3.add(52,7);
  s3.add(260,9);
  XYSeriesCollection data=new XYSeriesCollection();
  data.addSeries(s1);
  data.addSeries(s2);
  data.addSeries(s3);
  XYDataset dataset=data;
  JFreeChart chart = ChartFactory.createPolarChart
  ("Polar Chart",dataset,true,true, false);
  ChartFrame frame1=new ChartFrame("Polar Chart",chart);
  frame1.setVisible(true);
  frame1.setSize(300,300);
  }
}

Output of the Program :

Download this Program