Pie series

A pie chart displays information using sectors of a circle or ellipse to represent parts of the whole that is being displayed. Basically, there are four classes to be used to create a pie chart and set its properties. The pie chart context is represented by the PieGraph class. The sequence for creating a pie chart is the following:

  1. Create the pie chart context, creating an instance of the PieGraph class.
  2. Create a pie series with the PieSerie class and add the series to the pie chart context. Only one pie series is supported by the pie chart context.
  3. Create as many slices as necessary, using the Slice class, and add them to the pie series.
  4. Optionally, slice legends can be enabled. A slice legend is represented by the SliceLegend class.
The basic attributes of a pie slice are the color and value. A slice angle is directly proportional to the value it is associated with.

If any slice is clicked and dragged, two different actions might take place:
  1. If a slice is dragged, the pie chart is rotated.
  2. If a slice is dragged while the 'shift' key is held down, the slice is exploded.
To compile and run the example below, add the sPieChart.jar file to the system CLASSPATH variable.

import javax.swing.*;
import java.awt.*;
import com.jinsight.jetchart.*;

public class Main extends JFrame {

   public Main() { 
        
        PieGraph graph=new PieGraph();

	graph.set3DEnabled(true);

	PieSerie ps=new PieSerie();
	graph.addSerie(ps);       

	Color[] colors={Color.red,Color.green,Color.blue,Color.yellow};
	double[] values={50,80,40,90};
	String[] legends={"slice1","slice2","slice3","slice4"};	

	for (int counter=0;counter<values.length;counter++) {
	   Slice slice=new Slice(values[counter],legends[counter],colors[counter]);
	   ps.addSlice(slice);
	 }
	 
	 Container ct=getContentPane();

	 ct.add("Center",graph);

        setSize(500,400);

        setVisible(true);

  }

  public static void main(String[] args) {
        new Main();
  }

}