KickJava   Java API By Example, From Geeks To Geeks.

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


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

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.chart.ChartFactory;
41 import org.jfree.chart.ChartPanel;
42 import org.jfree.chart.JFreeChart;
43 import org.jfree.chart.plot.PlotOrientation;
44 import org.jfree.data.CategoryDataset;
45 import org.jfree.data.DefaultKeyedValues2DDataset;
46 import org.jfree.data.KeyedValues2DDataset;
47 import org.jfree.ui.ApplicationFrame;
48 import org.jfree.ui.RefineryUtilities;
49
50 /**
51  * A population pyramid demo.
52  *
53  * @author David Gilbert
54  */

55 public class PopulationChartDemo extends ApplicationFrame {
56
57     /**
58      * Creates a new demo.
59      *
60      * @param title the frame title.
61      */

62     public PopulationChartDemo(String JavaDoc title) {
63
64         super(title);
65         CategoryDataset dataset = createDataset();
66
67         // create the chart...
68
JFreeChart chart = ChartFactory.createStackedBarChart(
69             "Population Chart Demo",
70             "Age Group", // domain axis label
71
"Population (millions)", // range axis label
72
dataset, // data
73
PlotOrientation.HORIZONTAL,
74             true, // include legend
75
true, // tooltips
76
false // urls
77
);
78
79         // add the chart to a panel...
80
ChartPanel chartPanel = new ChartPanel(chart);
81         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
82         setContentPane(chartPanel);
83
84     }
85
86     // ****************************************************************************
87
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
88
// * Please note that commercial support and documentation is available from: *
89
// * *
90
// * http://www.object-refinery.com/jfreechart/support.html *
91
// * *
92
// * This is not only a great service for developers, but is a VERY IMPORTANT *
93
// * source of funding for the JFreeChart project. Please support us so that *
94
// * we can continue developing free software. *
95
// ****************************************************************************
96

97     /**
98      * Creates a dataset.
99      *
100      * @return A dataset.
101      */

102     private KeyedValues2DDataset createDataset() {
103
104         DefaultKeyedValues2DDataset data = new DefaultKeyedValues2DDataset();
105         data.addValue(-6.0, "Male", "70+");
106         data.addValue(-8.0, "Male", "60-69");
107         data.addValue(-11.0, "Male", "50-59");
108         data.addValue(-13.0, "Male", "40-49");
109         data.addValue(-14.0, "Male", "30-39");
110         data.addValue(-15.0, "Male", "20-29");
111         data.addValue(-19.0, "Male", "10-19");
112         data.addValue(-21.0, "Male", "0-9");
113         data.addValue(10.0, "Female", "70+");
114         data.addValue(12.0, "Female", "60-69");
115         data.addValue(13.0, "Female", "50-59");
116         data.addValue(14.0, "Female", "40-49");
117         data.addValue(15.0, "Female", "30-39");
118         data.addValue(17.0, "Female", "20-29");
119         data.addValue(19.0, "Female", "10-19");
120         data.addValue(20.0, "Female", "0-9");
121         return data;
122
123     }
124
125     /**
126      * Starting point for the demonstration application.
127      *
128      * @param args ignored.
129      */

130     public static void main(String JavaDoc[] args) {
131
132         PopulationChartDemo demo = new PopulationChartDemo("Population Chart Demo");
133         demo.pack();
134         RefineryUtilities.centerFrameOnScreen(demo);
135         demo.setVisible(true);
136
137     }
138
139 }
140
Popular Tags