KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TimeSeriesDemo6.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: TimeSeriesDemo6.java,v 1.6 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 08-Apr-2002 : Version 1 (DG);
35  * 25-Jun-2002 : Removed unnecessary import (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.text.SimpleDateFormat JavaDoc;
42
43 import org.jfree.chart.ChartFactory;
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.axis.DateAxis;
47 import org.jfree.chart.axis.ValueAxis;
48 import org.jfree.chart.plot.XYPlot;
49 import org.jfree.data.XYDataset;
50 import org.jfree.data.time.Month;
51 import org.jfree.data.time.TimeSeries;
52 import org.jfree.data.time.TimeSeriesCollection;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RefineryUtilities;
55
56 /**
57  * A time series chart with all zero data. When the data range is zero, you may want to modify
58  * the default behaviour of the range axis.
59  *
60  * @author David Gilbert
61  */

62 public class TimeSeriesDemo6 extends ApplicationFrame {
63
64     /**
65      * A demonstration application showing how to create a simple time series chart. This
66      * example uses monthly data.
67      *
68      * @param title the frame title.
69      */

70     public TimeSeriesDemo6(String JavaDoc title) {
71
72         super(title);
73         XYDataset dataset = createDataset();
74         JFreeChart chart = createChart(dataset);
75         ChartPanel chartPanel = new ChartPanel(chart);
76         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
77         setContentPane(chartPanel);
78
79     }
80
81     /**
82      * Creates a chart.
83      *
84      * @param dataset the dataset.
85      *
86      * @return a chart.
87      */

88     private JFreeChart createChart(XYDataset dataset) {
89         
90         JFreeChart chart = ChartFactory.createTimeSeriesChart(
91             "Time Series Demo 6",
92             "Date",
93             "Value",
94             dataset,
95             true,
96             true,
97             false
98         );
99
100         XYPlot plot = chart.getXYPlot();
101         DateAxis axis = (DateAxis) plot.getDomainAxis();
102         axis.setDateFormatOverride(new SimpleDateFormat JavaDoc("MMM-yyyy"));
103         ValueAxis rangeAxis = plot.getRangeAxis();
104         rangeAxis.setAutoRangeMinimumSize(1.0);
105         return chart;
106     
107     }
108     
109     // ****************************************************************************
110
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
111
// * Please note that commercial support and documentation is available from: *
112
// * *
113
// * http://www.object-refinery.com/jfreechart/support.html *
114
// * *
115
// * This is not only a great service for developers, but is a VERY IMPORTANT *
116
// * source of funding for the JFreeChart project. Please support us so that *
117
// * we can continue developing free software. *
118
// ****************************************************************************
119

120     /**
121      * Creates a dataset, consisting of two series of monthly data.
122      *
123      * @return the dataset.
124      */

125     public XYDataset createDataset() {
126
127         TimeSeries s1 = new TimeSeries("Series 1", Month.class);
128         s1.add(new Month(2, 2001), 0.0);
129         s1.add(new Month(3, 2001), 0.0);
130         s1.add(new Month(4, 2001), 0.0);
131         s1.add(new Month(5, 2001), 0.0);
132         s1.add(new Month(6, 2001), 0.0);
133         s1.add(new Month(7, 2001), 0.0);
134         s1.add(new Month(8, 2001), 0.0);
135         s1.add(new Month(9, 2001), 0.0);
136         s1.add(new Month(10, 2001), 0.0);
137         s1.add(new Month(11, 2001), 0.0);
138         s1.add(new Month(12, 2001), 0.0);
139         s1.add(new Month(1, 2002), 0.0);
140         s1.add(new Month(2, 2002), 0.0);
141         s1.add(new Month(3, 2002), 0.0);
142         s1.add(new Month(4, 2002), 0.0);
143         s1.add(new Month(5, 2002), 0.0);
144         s1.add(new Month(6, 2002), 0.0);
145         s1.add(new Month(7, 2002), 0.0);
146
147         TimeSeriesCollection dataset = new TimeSeriesCollection();
148         dataset.addSeries(s1);
149
150         return dataset;
151
152     }
153
154     /**
155      * Starting point for the demonstration application.
156      *
157      * @param args ignored.
158      */

159     public static void main(String JavaDoc[] args) {
160
161         TimeSeriesDemo6 demo = new TimeSeriesDemo6("Time Series Demo 6");
162         demo.pack();
163         RefineryUtilities.centerFrameOnScreen(demo);
164         demo.setVisible(true);
165
166     }
167
168 }
169
Popular Tags