KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MultiPieChartDemo.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: MultiPieChartDemo.java,v 1.8 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 21-Aug-2002 : Version 1 (DG);
35  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.awt.Color JavaDoc;
42
43 import org.jfree.chart.ChartFactory;
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.plot.PiePlot;
47 import org.jfree.data.CategoryDataset;
48 import org.jfree.data.DatasetUtilities;
49 import org.jfree.ui.ApplicationFrame;
50 import org.jfree.ui.RefineryUtilities;
51
52 /**
53  * A simple demonstration application showing how to create a chart consisting of multiple
54  * pie charts.
55  *
56  * @author David Gilbert
57  */

58 public class MultiPieChartDemo extends ApplicationFrame {
59
60     /**
61      * Creates a new demo.
62      *
63      * @param title the frame title.
64      */

65     public MultiPieChartDemo(String JavaDoc title) {
66
67         super(title);
68
69         // create a dataset...
70
double[][] data = new double[][] {
71             {3.0, 4.0, 3.0, 5.0},
72             {5.0, 7.0, 6.0, 8.0},
73             {5.0, 7.0, 3.0, 8.0},
74             {1.0, 2.0, 3.0, 4.0},
75             {2.0, 3.0, 2.0, 3.0}
76         };
77
78         CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
79             "Region ",
80             "Sales/Q",
81             data
82         );
83
84         // create the chart...
85
JFreeChart chart = ChartFactory.createPieChart(
86             "Multi Pie Chart", // chart title
87
dataset, // data
88
PiePlot.PER_ROW,
89             true, // include legend
90
true,
91             false
92         );
93
94         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
95

96         chart.setBackgroundPaint(Color.yellow);
97         PiePlot plot = (PiePlot) chart.getPlot();
98         plot.setSectionLabelType(PiePlot.VALUE_AND_PERCENT_LABELS);
99
100         // OPTIONAL CUSTOMISATION COMPLETED.
101

102         // add the chart to a panel...
103
ChartPanel chartPanel = new ChartPanel(chart, true, true, true, false, true);
104         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(600, 380));
105         setContentPane(chartPanel);
106
107     }
108
109     // ****************************************************************************
110
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
111
// * Please note that commercial support and documentation is available from: *
112
// * *
113
// * http://www.object-refinery.com/jfreechart/support.html *
114
// * *
115
// * This is not only a great service for developers, but is a VERY IMPORTANT *
116
// * source of funding for the JFreeChart project. Please support us so that *
117
// * we can continue developing free software. *
118
// ****************************************************************************
119

120     /**
121      * Starting point for the demonstration application.
122      *
123      * @param args ignored.
124      */

125     public static void main(String JavaDoc[] args) {
126
127         MultiPieChartDemo demo = new MultiPieChartDemo("Multi Pie Chart Demo");
128         demo.pack();
129         RefineryUtilities.centerFrameOnScreen(demo);
130         demo.setVisible(true);
131
132     }
133
134 }
135
Popular Tags