KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TimeSeriesDemo2.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: TimeSeriesDemo2.java,v 1.6 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 08-Apr-2002 : 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.Marker;
44 import org.jfree.data.time.Quarter;
45 import org.jfree.data.time.TimeSeries;
46 import org.jfree.data.time.TimeSeriesCollection;
47 import org.jfree.ui.ApplicationFrame;
48 import org.jfree.ui.RefineryUtilities;
49
50 /**
51  * A demo showing a time series (quarterly data) with a <code>null</code> value. The
52  * <code>null</code> value causes a gap in the line connecting the data points.
53  *
54  * @author David Gilbert
55  */

56 public class TimeSeriesDemo2 extends ApplicationFrame {
57
58     /**
59      * A demonstration application showing a quarterly time series containing a null value.
60      *
61      * @param title the frame title.
62      */

63     public TimeSeriesDemo2(String JavaDoc title) {
64
65         super(title);
66
67         TimeSeries series = new TimeSeries("Quarterly Data", Quarter.class);
68         series.add(new Quarter(1, 2001), 500.2);
69         series.add(new Quarter(2, 2001), 694.1);
70         series.add(new Quarter(3, 2001), 734.4);
71         series.add(new Quarter(4, 2001), 453.2);
72         series.add(new Quarter(1, 2002), 500.2);
73         series.add(new Quarter(2, 2002), null);
74         series.add(new Quarter(3, 2002), 734.4);
75         series.add(new Quarter(4, 2002), 453.2);
76         TimeSeriesCollection dataset = new TimeSeriesCollection(series);
77         JFreeChart chart = ChartFactory.createTimeSeriesChart(
78             "Time Series Demo 2",
79             "Time",
80             "Value",
81             dataset,
82             true,
83             true,
84             false
85         );
86         chart.getXYPlot().addRangeMarker(new Marker(550));
87         Quarter q = new Quarter(2, 2002);
88         chart.getXYPlot().addDomainMarker(new Marker(q.getMiddleMillisecond()));
89         ChartPanel chartPanel = new ChartPanel(chart);
90         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
91         setContentPane(chartPanel);
92
93     }
94
95     // ****************************************************************************
96
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
97
// * Please note that commercial support and documentation is available from: *
98
// * *
99
// * http://www.object-refinery.com/jfreechart/support.html *
100
// * *
101
// * This is not only a great service for developers, but is a VERY IMPORTANT *
102
// * source of funding for the JFreeChart project. Please support us so that *
103
// * we can continue developing free software. *
104
// ****************************************************************************
105

106     /**
107      * Starting point for the demonstration application.
108      *
109      * @param args ignored.
110      */

111     public static void main(String JavaDoc[] args) {
112
113         TimeSeriesDemo2 demo = new TimeSeriesDemo2("Time Series Demo 2");
114         demo.pack();
115         RefineryUtilities.centerFrameOnScreen(demo);
116         demo.setVisible(true);
117
118     }
119
120 }
121
Popular Tags