KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 package org.jfree.chart.demo;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.Date JavaDoc;
43 import java.util.List 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.plot.PlotOrientation;
49 import org.jfree.data.statistics.BoxAndWhiskerCalculator;
50 import org.jfree.data.statistics.BoxAndWhiskerXYDataset;
51 import org.jfree.data.statistics.DefaultBoxAndWhiskerXYDataset;
52 import org.jfree.date.DateUtilities;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RefineryUtilities;
55
56 /**
57  * A demo showing a box and whisker chart.
58  *
59  * @author David David Browning
60  */

61 public class XYBoxAndWhiskerDemo extends ApplicationFrame {
62
63     /**
64      * A demonstration application showing a box and whisker chart.
65      *
66      * @param title the frame title.
67      */

68     public XYBoxAndWhiskerDemo(String JavaDoc title) {
69
70         super(title);
71
72         BoxAndWhiskerXYDataset dataset = createSampleDataset();
73         JFreeChart chart = createChart(dataset);
74         chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
75         ChartPanel chartPanel = new ChartPanel(chart);
76         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(600, 400));
77         setContentPane(chartPanel);
78
79     }
80
81     /**
82      * Creates a chart.
83      *
84      * @param dataset the dataset.
85      *
86      * @return The dataset.
87      */

88     private JFreeChart createChart(BoxAndWhiskerXYDataset dataset) {
89         
90         JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(
91             "Box-and-Whisker Demo",
92             "Time",
93             "Value",
94             dataset,
95             true
96         );
97         return chart;
98         
99     }
100     
101     // ****************************************************************************
102
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
103
// * Please note that commercial support and documentation is available from: *
104
// * *
105
// * http://www.object-refinery.com/jfreechart/support.html *
106
// * *
107
// * This is not only a great service for developers, but is a VERY IMPORTANT *
108
// * source of funding for the JFreeChart project. Please support us so that *
109
// * we can continue developing free software. *
110
// ****************************************************************************
111

112     /**
113      * Creates a sample {@link BoxAndWhiskerDataset}.
114      *
115      * @return A sample dataset.
116      */

117     public static BoxAndWhiskerXYDataset createSampleDataset() {
118         
119         final int ENTITY_COUNT = 14;
120
121         DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("Test");
122         for (int i = 0; i < ENTITY_COUNT; i++) {
123             Date JavaDoc date = DateUtilities.createDate(2003, 7, i + 1, 12, 0);
124             List JavaDoc values = new ArrayList JavaDoc();
125             for (int j = 0; j < 10; j++) {
126                 values.add(new Double JavaDoc(10.0 + Math.random() * 10.0));
127                 values.add(new Double JavaDoc(13.0 + Math.random() * 4.0));
128             }
129             dataset.add(date, BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values));
130            
131         }
132
133         return dataset;
134     }
135
136     /**
137      * Starting point for the demonstration application.
138      *
139      * @param args ignored.
140      */

141     public static void main(String JavaDoc[] args) {
142
143         XYBoxAndWhiskerDemo demo = new XYBoxAndWhiskerDemo("Box-and-Whisker Demo");
144         demo.pack();
145         RefineryUtilities.centerFrameOnScreen(demo);
146         demo.setVisible(true);
147
148     }
149
150 }
151
152
Popular Tags