10. Using Pie Chart



The Pie Chart is different from the other charts in terms of the input data that it receives. It accepts only a single dimensional array of data for plotting the graph. Each value is plotted as a slice of a complete circle.

 

Significant features of Pie Chart

 

 

Example Implementation :

 

An example to Represent the Percentage of Revenues generated by different Products, is given below that illustrates plotting of sample data in the Pie chart. The plotting of data can be achieved in two ways:

 

 

The Input Data : The input data is the percentage of revenues generated by different products for a particular company (Maruthi Udyog Pvt. Ltd.). The table below shows the revenue generated by the different products of Maruti Udyog Pvt.Ltd., that are to be plotted.

 

Cars

Zen

800

Esteem

Balino

Alto

Others

% revenue

27.40

15.74

8.25

13.08

3.94

31.61

 

Viewing the Output : The data representing the revenues generated by the different products are plotted in the below shown Pie chart.

 

 

Implementing a Scatter Chart by manual coding

 

The steps to write a code to plot the required chart are given below.

 

 

import java.awt.*;

import javax.swing.*;

import com.adventnet.beans.charts.*;

 

 

AdventNetPieChart ch =null;

 

 

setLayout(new BorderLayout());

ch = new AdventNetPieChart();

 

 

ch.setNumberOfArcs(6);

 

 

ch.setItemValues(new double[] {27.4,15.74,8.25,13.08,3.94,31.61});

 

 

ch.setItemLabels(new String[] {"Zen","800","Esteem","Balino","Alto","Others",});

 

 

ch.setLegendVisible(true);

ch.setLegendTitle("Cars List");

 

 

ch.setView3D("10,45,45");

 

 

The complete code to construct the Pie chart can be seen for better understanding of the parameter settings. You can compile and run the code to see the above screen.

 

Implementing a Scatter Chart using Bean Builder IDE

 

 

Thus the Pie chart can be plotted and the methods / properties in it can be used for much more customization. You can refer to the Javadocs to use the other methods in the Pie chart.



Copyright © 1996-2002, AdventNet Inc. All Rights Reserved.