KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > swt > demo > SWTPieChartDemo1


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------
28  * SWTPieChartDemo1.java
29  * ---------------------
30  * (C) Copyright 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s):
34  *
35  * Changes
36  * -------
37  * 23-Aug-2006 : New class (DG);
38  *
39  */

40
41 package org.jfree.experimental.chart.swt.demo;
42
43 import java.awt.Font JavaDoc;
44
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.layout.FillLayout;
47 import org.eclipse.swt.widgets.Display;
48 import org.eclipse.swt.widgets.Shell;
49 import org.jfree.chart.ChartFactory;
50 import org.jfree.chart.JFreeChart;
51 import org.jfree.chart.plot.PiePlot;
52 import org.jfree.data.general.DefaultPieDataset;
53 import org.jfree.data.general.PieDataset;
54 import org.jfree.experimental.chart.swt.ChartComposite;
55
56 /**
57  * This demo shows a time series chart that has multiple range axes.
58  */

59 public class SWTPieChartDemo1 {
60     
61     /**
62      * Creates a sample dataset.
63      *
64      * @return A sample dataset.
65      */

66     private static PieDataset createDataset() {
67         DefaultPieDataset dataset = new DefaultPieDataset();
68         dataset.setValue("One", new Double JavaDoc(43.2));
69         dataset.setValue("Two", new Double JavaDoc(10.0));
70         dataset.setValue("Three", new Double JavaDoc(27.5));
71         dataset.setValue("Four", new Double JavaDoc(17.5));
72         dataset.setValue("Five", new Double JavaDoc(11.0));
73         dataset.setValue("Six", new Double JavaDoc(19.4));
74         return dataset;
75     }
76     
77     /**
78      * Creates a chart.
79      *
80      * @param dataset the dataset.
81      *
82      * @return A chart.
83      */

84     private static JFreeChart createChart(PieDataset dataset) {
85         
86         JFreeChart chart = ChartFactory.createPieChart(
87             "Pie Chart Demo 1", // chart title
88
dataset, // data
89
true, // include legend
90
true,
91             false
92         );
93
94         PiePlot plot = (PiePlot) chart.getPlot();
95         plot.setSectionOutlinesVisible(false);
96         plot.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 12));
97         plot.setNoDataMessage("No data available");
98         plot.setCircular(false);
99         plot.setLabelGap(0.02);
100         return chart;
101         
102     }
103     
104     /**
105      * Starting point for the demonstration application.
106      *
107      * @param args ignored.
108      */

109     public static void main( String JavaDoc[] args )
110     {
111         JFreeChart chart = createChart(createDataset());
112         Display display = new Display();
113         Shell shell = new Shell(display);
114         shell.setSize(600, 300);
115         shell.setLayout(new FillLayout());
116         shell.setText("Test for jfreechart running with SWT");
117         final ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart,
118                 false);
119         frame.pack();
120         shell.open();
121         while (!shell.isDisposed()) {
122             if (!display.readAndDispatch())
123                 display.sleep();
124         }
125     }
126
127 }
128
129
Popular Tags