JMSL Chart Programmer’s Guide
Pie Chart
A pie chart is a graphical way to organize data. This section describes the construction of a pie chart.
The JFrameChart class is used to create a frame containing a Chart node. A Pie node is then created as a child of the Chart node. The Pie node constructor creates PieSlice nodes as its children. The number of PieSlice nodes created is y.length, here equal to 4. After the PieSlice nodes are created they are retrieved from the object pie and customized by setting attributes.
The LabelType (setLabelType) attribute is set in the pie node. The pie node itself does not use this attribute, but from there it is inherited by all of the PieSlice nodes.
The Title attribute is set in each PieSlice node. This is the slice label. It is used to label the slice only if the slice’s LabelType attribute is LABEL_TYPE_TITLE.
The FillColor (setFillColor) attribute is also set in each slice. This determines the color of the slice. Since the default value of FillColor is black, it is generally recommended that FillColor be set in each slice.
The FillOutlineColor (setFillOutlineColor) attribute sets the border color of each slice. In this example it is set in the pie node to be blue and set in the slice[1] node to be yellow. All except slice[1] are outlined in blue, and slice[1] is outlined in yellow.
The Explode (setExplode) attribute moves a pie slice out from the center. Its default value is 0, which puts the slice vertex in the center. A value of 1.0 would put the slice vertex on the circumference.
View code file
import com.imsl.chart.*;
import java.awt.Color;
public class SamplePieChart extends JFrameChart {
public SamplePieChart() {
Chart chart = getChart();
double y[] = {35., 20., 30., 5.};
Pie pie = new Pie(chart, y);
pie.setViewport(0.0, 1.0, 0.0, 1.0);
PieSlice[] slice = pie.getPieSlice();
public static void main(String argv[]) {
new SamplePieChart().setVisible(true);