KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PieChartDemo4.java
24  * ------------------
25  * (C) Copyright 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: PieChartDemo4.java,v 1.11 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 11-Feb-2003 : Version 1 (DG);
35  *
36  */

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

57 public class PieChartDemo4 extends ApplicationFrame {
58
59     /**
60      * Default constructor.
61      *
62      * @param title the frame title.
63      */

64     public PieChartDemo4(String JavaDoc title) {
65
66         super(title);
67
68         // create a dataset...
69
DefaultPieDataset data = new DefaultPieDataset();
70         data.setValue("One", new Double JavaDoc(43.2));
71         data.setValue("Two", new Double JavaDoc(10.0));
72         data.setValue("Three", new Double JavaDoc(27.5));
73         data.setValue("Four", new Double JavaDoc(17.5));
74         data.setValue("Five", new Double JavaDoc(11.0));
75         data.setValue("Six", new Double JavaDoc(19.4));
76         data.setValue("Seven", new Double JavaDoc(19.4));
77         data.setValue("Eight", new Double JavaDoc(19.4));
78         data.setValue("Nine", new Double JavaDoc(9.4));
79         data.setValue("Ten", new Double JavaDoc(19.4));
80         data.setValue("Eleven", new Double JavaDoc(9.4));
81         data.setValue("Twelve", new Double JavaDoc(9.4));
82         data.setValue("Thirteen", new Double JavaDoc(9.4));
83         data.setValue("Fourteen", new Double JavaDoc(9.4));
84
85         // create the chart...
86
JFreeChart chart = ChartFactory.createPieChart(
87             "Pie Chart Demo 4", // chart title
88
data, // data
89
true, // include legend
90
true,
91             false
92         );
93
94         // set the background color for the chart...
95
chart.setBackgroundPaint(Color.yellow);
96         PiePlot plot = (PiePlot) chart.getPlot();
97         plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
98         plot.setNoDataMessage("No data available");
99         plot.setItemLabelGenerator(new StandardPieItemLabelGenerator());
100         plot.setSectionPaint(0, new Color JavaDoc(0xCC, 0xCC, 0xFF));
101         plot.setSectionPaint(1, new Color JavaDoc(0xFF, 0xCC, 0xCC));
102         plot.setSectionPaint(2, new Color JavaDoc(0xCC, 0xFF, 0xCC));
103         plot.setSectionPaint(3, new Color JavaDoc(0xFF, 0x99, 0x99));
104         plot.setSectionPaint(4, new Color JavaDoc(0x99, 0xFF, 0x99));
105         plot.setSectionPaint(5, new Color JavaDoc(0x99, 0x99, 0xFF));
106
107         plot.setSectionOutlinePaint(null);
108         plot.setSectionOutlinePaintListAutoFill(false);
109
110         // add the chart to a panel...
111
ChartPanel chartPanel = new ChartPanel(chart);
112         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
113         setContentPane(chartPanel);
114
115     }
116
117     // ****************************************************************************
118
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
119
// * Please note that commercial support and documentation is available from: *
120
// * *
121
// * http://www.object-refinery.com/jfreechart/support.html *
122
// * *
123
// * This is not only a great service for developers, but is a VERY IMPORTANT *
124
// * source of funding for the JFreeChart project. Please support us so that *
125
// * we can continue developing free software. *
126
// ****************************************************************************
127

128     /**
129      * Starting point for the demonstration application.
130      *
131      * @param args ignored.
132      */

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