KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TimeSeriesDemo5.java
24  * --------------------
25  * (C) Copyright 2001-2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: TimeSeriesDemo5.java,v 1.7 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes (from 24-Apr-2002)
33  * --------------------------
34  * 24-Apr-2002 : Added standard header (DG);
35  * 10-Oct-2002 : Renamed JFreeChartDemo2 --> TimeSeriesDemo5 (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import org.jfree.chart.ChartFactory;
42 import org.jfree.chart.ChartFrame;
43 import org.jfree.chart.JFreeChart;
44 import org.jfree.data.SeriesException;
45 import org.jfree.data.XYDataset;
46 import org.jfree.data.time.Day;
47 import org.jfree.data.time.TimeSeries;
48 import org.jfree.data.time.TimeSeriesCollection;
49 import org.jfree.ui.RefineryUtilities;
50
51 /**
52  * A time series chart with 4000 data points, to get an idea of how JFreeChart performs with a
53  * larger dataset. You can see that it slows down significantly, so this needs to be worked on
54  * (4000 points is not that many!).
55  *
56  * @author David Gilbert
57  */

58 public class TimeSeriesDemo5 {
59
60     // ****************************************************************************
61
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
62
// * Please note that commercial support and documentation is available from: *
63
// * *
64
// * http://www.object-refinery.com/jfreechart/support.html *
65
// * *
66
// * This is not only a great service for developers, but is a VERY IMPORTANT *
67
// * source of funding for the JFreeChart project. Please support us so that *
68
// * we can continue developing free software. *
69
// ****************************************************************************
70

71     /**
72      * Starting point for the application.
73      *
74      * @param args ignored.
75      */

76     public static void main(String JavaDoc[] args) {
77
78         TimeSeries series = new TimeSeries("Random Data");
79
80         Day current = new Day(1, 1, 1990);
81         double value = 100.0;
82
83         for (int i = 0; i < 4000; i++) {
84             try {
85                 value = value + Math.random() - 0.5;
86                 series.add(current, new Double JavaDoc(value));
87                 current = (Day) current.next();
88             }
89             catch (SeriesException e) {
90                 System.err.println("Error adding to series");
91             }
92         }
93
94         XYDataset data = new TimeSeriesCollection(series);
95
96         JFreeChart chart = ChartFactory.createTimeSeriesChart(
97             "Test",
98             "Day",
99             "Value",
100             data,
101             false,
102             false,
103             false
104         );
105
106         ChartFrame frame = new ChartFrame(
107             "\u20A2\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA", chart
108         );
109         frame.pack();
110         RefineryUtilities.positionFrameRandomly(frame);
111         frame.setVisible(true);
112
113     }
114
115 }
116
Popular Tags