KickJava   Java API By Example, From Geeks To Geeks.

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


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

39
40 package org.jfree.chart.demo;
41
42 import java.awt.BasicStroke JavaDoc;
43 import java.awt.Color JavaDoc;
44 import java.awt.Insets JavaDoc;
45
46 import org.jfree.chart.ChartFactory;
47 import org.jfree.chart.ChartPanel;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.chart.Marker;
50 import org.jfree.chart.plot.XYPlot;
51 import org.jfree.chart.renderer.StandardXYItemRenderer;
52 import org.jfree.chart.renderer.XYItemRenderer;
53 import org.jfree.data.time.Day;
54 import org.jfree.data.time.Hour;
55 import org.jfree.data.time.TimeSeries;
56 import org.jfree.data.time.TimeSeriesCollection;
57 import org.jfree.ui.ApplicationFrame;
58 import org.jfree.ui.RefineryUtilities;
59
60 /**
61  * An example of a time series chart using hourly data and including a null value. The plot
62  * has an image set for the background, and a blue range marker is added to the plot.
63  *
64  * @author David Gilbert
65  */

66 public class TimeSeriesDemo4 extends ApplicationFrame {
67
68     /**
69      * A demonstration application showing a quarterly time series containing a null value.
70      *
71      * @param title the frame title.
72      */

73     public TimeSeriesDemo4(String JavaDoc title) {
74
75         super(title);
76         TimeSeries series = new TimeSeries("Random Data", Hour.class);
77         Day today = new Day();
78         series.add(new Hour(1, today), 500.2);
79         series.add(new Hour(2, today), 694.1);
80         series.add(new Hour(3, today), 734.4);
81         series.add(new Hour(4, today), 453.2);
82         series.add(new Hour(7, today), 500.2);
83         series.add(new Hour(8, today), null);
84         series.add(new Hour(12, today), 734.4);
85         series.add(new Hour(16, today), 453.2);
86         TimeSeriesCollection dataset = new TimeSeriesCollection(series);
87
88         // create a title with Unicode characters (currency symbols in this case)...
89
String JavaDoc chartTitle = "\u20A2\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA";
90         JFreeChart chart = ChartFactory.createTimeSeriesChart(
91             chartTitle,
92             "Time",
93             "Value",
94             dataset,
95             true,
96             true,
97             false
98         );
99
100         XYPlot plot = chart.getXYPlot();
101         plot.setInsets(new Insets JavaDoc(0, 0, 0, 20));
102         plot.addRangeMarker(new Marker(700, Color.blue, new BasicStroke JavaDoc(1.0f), Color.blue, 0.8f));
103         plot.setBackgroundPaint(null);
104         plot.setBackgroundImage(JFreeChart.INFO.getLogo());
105         XYItemRenderer renderer = plot.getRenderer();
106         if (renderer instanceof StandardXYItemRenderer) {
107             StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
108             r.setPlotShapes(true);
109             r.setShapesFilled(true);
110         }
111         ChartPanel chartPanel = new ChartPanel(chart);
112         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
113         chartPanel.setMouseZoomable(true, false);
114         setContentPane(chartPanel);
115
116     }
117
118     // ****************************************************************************
119
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
120
// * Please note that commercial support and documentation is available from: *
121
// * *
122
// * http://www.object-refinery.com/jfreechart/support.html *
123
// * *
124
// * This is not only a great service for developers, but is a VERY IMPORTANT *
125
// * source of funding for the JFreeChart project. Please support us so that *
126
// * we can continue developing free software. *
127
// ****************************************************************************
128

129     /**
130      * Starting point for the demonstration application.
131      *
132      * @param args ignored.
133      */

134     public static void main(String JavaDoc[] args) {
135
136         TimeSeriesDemo4 demo = new TimeSeriesDemo4("Time Series Demo 4");
137         demo.pack();
138         RefineryUtilities.centerFrameOnScreen(demo);
139         demo.setVisible(true);
140
141     }
142
143 }
144
Popular Tags