KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > PieChartDemo1


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ------------------
27  * PieChartDemo1.java
28  * ------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): ;
33  *
34  * $Id: PieChartDemo1.java,v 1.2 2005/03/28 19:38:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 09-Mar-2005 : Version 1, copied from the demo collection that ships with
39  * the JFreeChart Developer Guide (DG);
40  *
41  */

42
43 package org.jfree.chart.demo;
44
45 import java.awt.Font JavaDoc;
46
47 import javax.swing.JPanel JavaDoc;
48
49 import org.jfree.chart.ChartFactory;
50 import org.jfree.chart.ChartPanel;
51 import org.jfree.chart.JFreeChart;
52 import org.jfree.chart.plot.PiePlot;
53 import org.jfree.data.general.DefaultPieDataset;
54 import org.jfree.data.general.PieDataset;
55 import org.jfree.ui.ApplicationFrame;
56 import org.jfree.ui.RefineryUtilities;
57
58 /**
59  * A simple demonstration application showing how to create a pie chart using
60  * data from a {@link DefaultPieDataset}.
61  */

62 public class PieChartDemo1 extends ApplicationFrame {
63
64     /**
65      * Default constructor.
66      *
67      * @param title the frame title.
68      */

69     public PieChartDemo1(String JavaDoc title) {
70         super(title);
71         setContentPane(createDemoPanel());
72     }
73
74     /**
75      * Creates a sample dataset.
76      *
77      * @return A sample dataset.
78      */

79     private static PieDataset createDataset() {
80         DefaultPieDataset dataset = new DefaultPieDataset();
81         dataset.setValue("One", new Double JavaDoc(43.2));
82         dataset.setValue("Two", new Double JavaDoc(10.0));
83         dataset.setValue("Three", new Double JavaDoc(27.5));
84         dataset.setValue("Four", new Double JavaDoc(17.5));
85         dataset.setValue("Five", new Double JavaDoc(11.0));
86         dataset.setValue("Six", new Double JavaDoc(19.4));
87         return dataset;
88     }
89     
90     /**
91      * Creates a chart.
92      *
93      * @param dataset the dataset.
94      *
95      * @return A chart.
96      */

97     private static JFreeChart createChart(PieDataset dataset) {
98         
99         JFreeChart chart = ChartFactory.createPieChart(
100             "Pie Chart Demo 1", // chart title
101
dataset, // data
102
true, // include legend
103
true,
104             false
105         );
106
107         PiePlot plot = (PiePlot) chart.getPlot();
108         plot.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 12));
109         plot.setNoDataMessage("No data available");
110         plot.setCircular(false);
111         plot.setLabelGap(0.02);
112         return chart;
113         
114     }
115     
116     /**
117      * Creates a panel for the demo (used by SuperDemo.java).
118      *
119      * @return A panel.
120      */

121     public static JPanel JavaDoc createDemoPanel() {
122         JFreeChart chart = createChart(createDataset());
123         return new ChartPanel(chart);
124     }
125     
126     /**
127      * Starting point for the demonstration application.
128      *
129      * @param args ignored.
130      */

131     public static void main(String JavaDoc[] args) {
132
133         PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
134         demo.pack();
135         RefineryUtilities.centerFrameOnScreen(demo);
136         demo.setVisible(true);
137
138     }
139
140 }
141
Popular Tags