KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------
23  * Pie3DChartDemo1.java
24  * --------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: Pie3DChartDemo1.java,v 1.7 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 19-Jun-2002 : Version 1 (DG);
35  * 31-Jul-2002 : Updated with changes to Pie3DPlot class (DG);
36  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
37  *
38  */

39
40 package org.jfree.chart.demo;
41
42 import java.awt.Color JavaDoc;
43
44 import org.jfree.chart.ChartFactory;
45 import org.jfree.chart.ChartPanel;
46 import org.jfree.chart.JFreeChart;
47 import org.jfree.chart.plot.Pie3DPlot;
48 import org.jfree.data.DefaultPieDataset;
49 import org.jfree.data.PieDataset;
50 import org.jfree.ui.ApplicationFrame;
51 import org.jfree.ui.RefineryUtilities;
52 import org.jfree.util.Rotation;
53
54 /**
55  * A simple demonstration application showing how to create a pie chart using data from a
56  * {@link DefaultPieDataset}.
57  *
58  * @author David Gilbert
59  */

60 public class Pie3DChartDemo1 extends ApplicationFrame {
61
62     /**
63      * Creates a new demo.
64      *
65      * @param title the frame title.
66      */

67     public Pie3DChartDemo1(String JavaDoc title) {
68
69         super(title);
70
71         // create a dataset...
72
PieDataset dataset = createSampleDataset();
73         
74         // create the chart...
75
JFreeChart chart = createChart(dataset);
76         
77         // add the chart to a panel...
78
ChartPanel chartPanel = new ChartPanel(chart);
79         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
80         setContentPane(chartPanel);
81
82     }
83     
84     /**
85      * Creates a sample dataset for the demo.
86      *
87      * @return A sample dataset.
88      */

89     private PieDataset createSampleDataset() {
90         
91         DefaultPieDataset result = new DefaultPieDataset();
92         result.setValue("Java", new Double JavaDoc(43.2));
93         result.setValue("Visual Basic", new Double JavaDoc(10.0));
94         result.setValue("C/C++", new Double JavaDoc(17.5));
95         result.setValue("PHP", new Double JavaDoc(32.5));
96         result.setValue("Perl", new Double JavaDoc(0.0));
97         return result;
98         
99     }
100     
101     // ****************************************************************************
102
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
103
// * Please note that commercial support and documentation is available from: *
104
// * *
105
// * http://www.object-refinery.com/jfreechart/support.html *
106
// * *
107
// * This is not only a great service for developers, but is a VERY IMPORTANT *
108
// * source of funding for the JFreeChart project. Please support us so that *
109
// * we can continue developing free software. *
110
// ****************************************************************************
111

112     /**
113      * Creates a sample chart.
114      *
115      * @param dataset the dataset.
116      *
117      * @return A chart.
118      */

119     private JFreeChart createChart(PieDataset dataset) {
120         
121         JFreeChart chart = ChartFactory.createPie3DChart(
122             "Pie Chart 3D Demo 1", // chart title
123
dataset, // data
124
true, // include legend
125
true,
126             false
127         );
128
129         // set the background color for the chart...
130
chart.setBackgroundPaint(Color.yellow);
131         Pie3DPlot plot = (Pie3DPlot) chart.getPlot();
132         plot.setStartAngle(270);
133         plot.setDirection(Rotation.CLOCKWISE);
134         plot.setForegroundAlpha(0.5f);
135         plot.setNoDataMessage("No data to display");
136         
137         return chart;
138         
139     }
140     
141     /**
142      * Starting point for the demonstration application.
143      *
144      * @param args ignored.
145      */

146     public static void main(String JavaDoc[] args) {
147
148         Pie3DChartDemo1 demo = new Pie3DChartDemo1("Pie Chart 3D Demo 1");
149         demo.pack();
150         RefineryUtilities.centerFrameOnScreen(demo);
151         demo.setVisible(true);
152
153     }
154
155 }
156
Popular Tags