In this section we are providing you an example to create a Pie Chart.
Description of Example
For creating a Pie Chart we use PieDataset. In this example, for creating a PieDataset we are using DefaultPieDataset class. Then we add some data in this dataset that will show in chart.
Description of Code
DefaultPieDataset pieDataset = new DefaultPieDataset();
For defining a dataset for a pie chart we have to create an object of DefaultPieDataSet type :
setValue(?one?, new Integer(10));
After creating the instance of dataset then we have to add the data in the data set by invoking the method setValue(). Like
JFreeChart chart = ChartFactory.createPieChart("Pie Chart using JFreeChart", pieDataset true, true, true);
After added the data in dataset we create the Pie Chart by invoking the createPieChart() 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 createPieChart(java.lang.String title, pieDataset dataset, boolean legend, boolean tooltips, boolean urls);
After this we create the object of ChartFrame. It used to display a chart.
Here is code of the program :
Output of the Program :
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.