KickJava   Java API By Example, From Geeks To Geeks.

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


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

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.chart.ChartPanel;
41 import org.jfree.chart.JFreeChart;
42 import org.jfree.chart.axis.DateAxis;
43 import org.jfree.chart.axis.NumberAxis;
44 import org.jfree.chart.axis.ValueAxis;
45 import org.jfree.chart.plot.XYPlot;
46 import org.jfree.chart.renderer.XYBarRenderer;
47 import org.jfree.chart.renderer.XYItemRenderer;
48 import org.jfree.data.XYDataset;
49 import org.jfree.data.time.Day;
50 import org.jfree.data.time.SimpleTimePeriod;
51 import org.jfree.data.time.TimePeriodValues;
52 import org.jfree.data.time.TimePeriodValuesCollection;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RefineryUtilities;
55
56 /**
57  * An example of....
58  *
59  * @author David Gilbert
60  */

61 public class TimePeriodValuesDemo2 extends ApplicationFrame {
62
63     /**
64      * A demonstration application showing how to....
65      *
66      * @param title the frame title.
67      */

68     public TimePeriodValuesDemo2(String JavaDoc title) {
69
70         super(title);
71
72         XYDataset data1 = createDataset();
73         XYItemRenderer renderer1 = new XYBarRenderer();
74         
75         DateAxis domainAxis = new DateAxis("Date");
76         ValueAxis rangeAxis = new NumberAxis("Value");
77         
78         XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
79
80         JFreeChart chart = new JFreeChart("Time Period Values Demo", plot);
81         ChartPanel chartPanel = new ChartPanel(chart);
82         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
83         chartPanel.setMouseZoomable(true, false);
84         setContentPane(chartPanel);
85
86     }
87
88     // ****************************************************************************
89
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
90
// * Please note that commercial support and documentation is available from: *
91
// * *
92
// * http://www.object-refinery.com/jfreechart/support.html *
93
// * *
94
// * This is not only a great service for developers, but is a VERY IMPORTANT *
95
// * source of funding for the JFreeChart project. Please support us so that *
96
// * we can continue developing free software. *
97
// ****************************************************************************
98

99     /**
100      * Creates a dataset, consisting of two series of monthly data.
101      *
102      * @return the dataset.
103      */

104     public XYDataset createDataset() {
105
106         TimePeriodValues s1 = new TimePeriodValues("Series 1");
107         Day d1 = new Day();
108         Day d2 = (Day) d1.next();
109         Day d3 = (Day) d2.next();
110         Day d4 = (Day) d3.next();
111         Day d5 = (Day) d4.next();
112         Day d6 = (Day) d5.next();
113         Day d7 = (Day) d6.next();
114         
115         s1.add(new SimpleTimePeriod(d6.getStart(), d6.getEnd()), 74.95);
116         s1.add(new SimpleTimePeriod(d1.getStart(), d2.getEnd()), 55.75);
117         s1.add(new SimpleTimePeriod(d7.getStart(), d7.getEnd()), 90.45);
118         s1.add(new SimpleTimePeriod(d3.getStart(), d5.getEnd()), 105.75);
119
120         TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
121         dataset.addSeries(s1);
122         dataset.setDomainIsPointsInTime(false);
123
124         return dataset;
125
126     }
127
128     /**
129      * Starting point for the demonstration application.
130      *
131      * @param args ignored.
132      */

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