KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SimpleIntervalXYDataset2.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: SimpleIntervalXYDataset2.java,v 1.3 2003/09/03 15:08:49 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 27-jUN-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.data.AbstractDataset;
41 import org.jfree.data.DatasetChangeListener;
42 import org.jfree.data.IntervalXYDataset;
43
44 /**
45  * A quick and dirty sample dataset.
46  *
47  * @author David Gilbert
48  */

49 public class SimpleIntervalXYDataset2 extends AbstractDataset implements IntervalXYDataset {
50
51     /** The start values. */
52     private Double JavaDoc[] yStart;
53     
54     /** The end values. */
55     private Double JavaDoc[] yEnd = new Double JavaDoc[3];
56
57     /** The x values. */
58     private Double JavaDoc[] x = new Double JavaDoc[3];
59
60     /**
61      * Creates a new dataset.
62      *
63      * @param itemCount the number of items to generate.
64      */

65     public SimpleIntervalXYDataset2(int itemCount) {
66
67         x = new Double JavaDoc[itemCount];
68         yStart = new Double JavaDoc[itemCount];
69         yEnd = new Double JavaDoc[itemCount];
70         
71         double base = 100;
72         for (int i = 1; i <= itemCount; i++) {
73             x[i - 1] = new Double JavaDoc(i);
74             base = base * (1 + (Math.random() / 10 - 0.05));
75             yStart[i - 1] = new Double JavaDoc(base);
76             yEnd[i - 1] = new Double JavaDoc(yStart[i - 1].doubleValue() + Math.random() * 30);
77         }
78     }
79
80     /**
81      * Returns the number of series in the dataset.
82      *
83      * @return the number of series in the dataset.
84      */

85     public int getSeriesCount() {
86         return 1;
87     }
88
89     /**
90      * Returns the name of a series.
91      *
92      * @param series the series (zero-based index).
93      *
94      * @return the series name.
95      */

96     public String JavaDoc getSeriesName(int series) {
97         return "Series 1";
98     }
99
100     /**
101      * Returns the number of items in a series.
102      *
103      * @param series the series (zero-based index).
104      *
105      * @return the number of items within a series.
106      */

107     public int getItemCount(int series) {
108         return x.length;
109     }
110
111     /**
112      * Returns the x-value for an item within a series.
113      * <P>
114      * The implementation is responsible for ensuring that the x-values are presented in ascending
115      * order.
116      *
117      * @param series the series (zero-based index).
118      * @param item the item (zero-based index).
119      *
120      * @return the x-value for an item within a series.
121      */

122     public Number JavaDoc getXValue(int series, int item) {
123         return x[item];
124     }
125
126     /**
127      * Returns the y-value for an item within a series.
128      *
129      * @param series the series (zero-based index).
130      * @param item the item (zero-based index).
131      *
132      * @return the y-value for an item within a series.
133      */

134     public Number JavaDoc getYValue(int series, int item) {
135         return yEnd[item];
136     }
137
138     /**
139      * Returns the starting X value for the specified series and item.
140      *
141      * @param series the series (zero-based index).
142      * @param item the item within a series (zero-based index).
143      *
144      * @return the start x value.
145      */

146     public Number JavaDoc getStartXValue(int series, int item) {
147         return x[item];
148     }
149
150     /**
151      * Returns the ending X value for the specified series and item.
152      *
153      * @param series the series (zero-based index).
154      * @param item the item within a series (zero-based index).
155      *
156      * @return the end x value.
157      */

158     public Number JavaDoc getEndXValue(int series, int item) {
159         return x[item];
160     }
161
162     /**
163      * Returns the starting Y value for the specified series and item.
164      *
165      * @param series the series (zero-based index).
166      * @param item the item within a series (zero-based index).
167      *
168      * @return the start y value.
169      */

170     public Number JavaDoc getStartYValue(int series, int item) {
171         return yStart[item];
172     }
173
174     /**
175      * Returns the ending Y value for the specified series and item.
176      *
177      * @param series the series (zero-based index).
178      * @param item the item within a series (zero-based index).
179      *
180      * @return the end y value.
181      */

182     public Number JavaDoc getEndYValue(int series, int item) {
183         return yEnd[item];
184     }
185
186     /**
187      * Registers an object for notification of changes to the dataset.
188      *
189      * @param listener the object to register.
190      */

191     public void addChangeListener(DatasetChangeListener listener) {
192     }
193
194     /**
195      * Deregisters an object for notification of changes to the dataset.
196      *
197      * @param listener the object to deregister.
198      */

199     public void removeChangeListener(DatasetChangeListener listener) {
200     }
201
202 }
203
Popular Tags