KickJava   Java API By Example, From Geeks To Geeks.

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


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-2002, 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  * StatisticalBarChartDemo.java
24  * ----------------------------
25  * (C) Copyright 2002, 2003, by Pascal Collet and Contributors.
26  *
27  * Original Author: Pascal Collet;
28  * Contributor(s): David Gilbert (for Object Refinery Limited);
29  *
30  * $Id: StatisticalBarChartDemo.java,v 1.10 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 21-Aug-2002 : Version 1, contributed by Pascal Collet (DG);
35  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  * 05-Feb-2003 : Updated for documentation (DG);
37  *
38  */

39
40 package org.jfree.chart.demo;
41
42 import java.awt.Font JavaDoc;
43
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.axis.CategoryAxis;
47 import org.jfree.chart.axis.NumberAxis;
48 import org.jfree.chart.axis.ValueAxis;
49 import org.jfree.chart.plot.CategoryPlot;
50 import org.jfree.chart.renderer.CategoryItemRenderer;
51 import org.jfree.chart.renderer.StatisticalBarRenderer;
52 import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;
53 import org.jfree.data.statistics.StatisticalCategoryDataset;
54 import org.jfree.ui.ApplicationFrame;
55 import org.jfree.ui.RefineryUtilities;
56
57 /**
58  * Demonstration of the statistical bar graph.
59  *
60  * @author Pascal Collet
61  */

62 public class StatisticalBarChartDemo extends ApplicationFrame {
63
64     /**
65      * Creates a new demo.
66      *
67      * @param title the frame title.
68      */

69     public StatisticalBarChartDemo(String JavaDoc title) {
70
71         super(title);
72         StatisticalCategoryDataset dataset = createDataset();
73
74         CategoryAxis xAxis = new CategoryAxis("Type");
75         xAxis.setLowerMargin(0.01d); // percentage of space before first bar
76
xAxis.setUpperMargin(0.01d); // percentage of space after last bar
77
xAxis.setCategoryMargin(0.05d); // percentage of space between categories
78
ValueAxis yAxis = new NumberAxis("Value");
79
80         // define the plot
81
CategoryItemRenderer renderer = new StatisticalBarRenderer();
82         CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
83
84         JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo",
85                                           new Font JavaDoc("Helvetica", Font.BOLD, 14),
86                                           plot,
87                                           true);
88         //chart.setBackgroundPaint(Color.white);
89
// add the chart to a panel...
90
ChartPanel chartPanel = new ChartPanel(chart);
91         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
92         setContentPane(chartPanel);
93
94     }
95
96     // ****************************************************************************
97
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
98
// * Please note that commercial support and documentation is available from: *
99
// * *
100
// * http://www.object-refinery.com/jfreechart/support.html *
101
// * *
102
// * This is not only a great service for developers, but is a VERY IMPORTANT *
103
// * source of funding for the JFreeChart project. Please support us so that *
104
// * we can continue developing free software. *
105
// ****************************************************************************
106

107     /**
108      * Creates a sample dataset.
109      *
110      * @return The dataset.
111      */

112     private StatisticalCategoryDataset createDataset() {
113
114         DefaultStatisticalCategoryDataset result = new DefaultStatisticalCategoryDataset();
115
116         result.add(32.5, 17.9, "Series 1", "Type 1");
117         result.add(27.8, 11.4, "Series 1", "Type 2");
118         result.add(29.3, 14.4, "Series 1", "Type 3");
119         result.add(37.9, 10.3, "Series 1", "Type 4");
120
121         result.add(22.9, 7.9, "Series 2", "Type 1");
122         result.add(21.8, 18.4, "Series 2", "Type 2");
123         result.add(19.3, 12.4, "Series 2", "Type 3");
124         result.add(30.3, 20.7, "Series 2", "Type 4");
125
126         result.add(12.5, 10.9, "Series 3", "Type 1");
127         result.add(24.8, 7.4, "Series 3", "Type 2");
128         result.add(19.3, 13.4, "Series 3", "Type 3");
129         result.add(17.1, 10.6, "Series 3", "Type 4");
130
131         return result;
132
133     }
134
135     /**
136      * For testing from the command line.
137      *
138      * @param args ignored.
139      */

140     public static void main(String JavaDoc[] args) {
141
142         StatisticalBarChartDemo demo = new StatisticalBarChartDemo("Statistical Bar Chart Demo");
143         demo.pack();
144         RefineryUtilities.centerFrameOnScreen(demo);
145         demo.setVisible(true);
146
147     }
148
149 }
150
Popular Tags