KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XMLPieChartDemo.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: XMLPieChartDemo.java,v 1.8 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 20-Nov-2002 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.Color JavaDoc;
41 import java.io.IOException JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.net.URL JavaDoc;
44
45 import org.jfree.chart.ChartFactory;
46 import org.jfree.chart.ChartPanel;
47 import org.jfree.chart.JFreeChart;
48 import org.jfree.chart.labels.StandardPieItemLabelGenerator;
49 import org.jfree.chart.plot.PiePlot;
50 import org.jfree.data.PieDataset;
51 import org.jfree.data.xml.DatasetReader;
52 import org.jfree.ui.ApplicationFrame;
53 import org.jfree.ui.RefineryUtilities;
54
55 /**
56  * A simple demonstration application showing how to create a pie chart from data in an
57  * XML file.
58  *
59  * @author David Gilbert
60  */

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

68     public XMLPieChartDemo(String JavaDoc title) {
69
70         super(title);
71
72         // create a dataset...
73
PieDataset dataset = null;
74         URL JavaDoc url = getClass().getResource("/org/jfree/chart/demo/piedata.xml");
75
76         try {
77             InputStream JavaDoc in = url.openStream();
78             dataset = DatasetReader.readPieDatasetFromXML(in);
79         }
80         catch (IOException JavaDoc ioe) {
81             System.out.println(ioe.getMessage());
82         }
83
84         // create the chart...
85
JFreeChart chart = ChartFactory.createPieChart(
86             "Pie Chart Demo 1", // chart title
87
dataset, // data
88
true, // include legend
89
true,
90             false
91         );
92
93         // set the background color for the chart...
94
chart.setBackgroundPaint(Color.yellow);
95         PiePlot plot = (PiePlot) chart.getPlot();
96         plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
97         plot.setNoDataMessage("No data available");
98         plot.setItemLabelGenerator(new StandardPieItemLabelGenerator());
99
100         // add the chart to a panel...
101
ChartPanel chartPanel = new ChartPanel(chart);
102         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
103         setContentPane(chartPanel);
104
105     }
106
107     // ****************************************************************************
108
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
109
// * Please note that commercial support and documentation is available from: *
110
// * *
111
// * http://www.object-refinery.com/jfreechart/support.html *
112
// * *
113
// * This is not only a great service for developers, but is a VERY IMPORTANT *
114
// * source of funding for the JFreeChart project. Please support us so that *
115
// * we can continue developing free software. *
116
// ****************************************************************************
117

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

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