KickJava   Java API By Example, From Geeks To Geeks.

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


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

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.data.AbstractSeriesDataset;
41 import org.jfree.data.XYZDataset;
42
43 /**
44  * A quick-and-dirty implementation of the {@link XYZDataset interface}. Hard-coded and not useful
45  * beyond the demo.
46  *
47  * @author David Gilbert
48  */

49 public class SampleXYZDataset extends AbstractSeriesDataset implements XYZDataset {
50
51     /** The x values. */
52     private double[] xVal = {2.1, 2.375625, 2.375625, 2.232928726, 2.232928726, 1.860415253,
53                              1.840842668, 1.905415253, 2.336029412, 3.8};
54
55     /** The y values. */
56     private double[] yVal = {14.168, 11.156, 10.089, 8.884, 8.719, 8.466, 5.489,
57                              4.107, 4.101, 25};
58
59     /** The z values. */
60     private double[] zVal = {2.45, 2.791285714, 2.791285714, 2.2125, 2.2125, 2.22, 2.1, 2.22,
61                              1.64875, 4};
62
63     /**
64      * Returns the number of series in the dataset.
65      *
66      * @return the series count.
67      */

68     public int getSeriesCount() {
69         return 1;
70     }
71
72     /**
73      * Returns the name of a series.
74      *
75      * @param series the series (zero-based index).
76      *
77      * @return the name of the series.
78      */

79     public String JavaDoc getSeriesName(int series) {
80         return "Series 1";
81     }
82
83     /**
84      * Returns the number of items in a series.
85      *
86      * @param series the series (zero-based index).
87      *
88      * @return the number of items within the series.
89      */

90     public int getItemCount(int series) {
91         return xVal.length;
92     }
93
94     /**
95      * Returns the x-value for an item within a series.
96      * <P>
97      * The implementation is responsible for ensuring that the x-values are
98      * presented in ascending order.
99      *
100      * @param series the series (zero-based index).
101      * @param item the item (zero-based index).
102      *
103      * @return the x-value.
104      */

105     public Number JavaDoc getXValue(int series, int item) {
106         return new Double JavaDoc(xVal[item]);
107     }
108
109     /**
110      * Returns the y-value for an item within a series.
111      *
112      * @param series the series (zero-based index).
113      * @param item the item (zero-based index).
114      *
115      * @return the y-value.
116      */

117     public Number JavaDoc getYValue(int series, int item) {
118         return new Double JavaDoc(yVal[item]);
119     }
120
121     /**
122      * Returns the z-value for the specified series and item.
123      *
124      * @param series the series (zero-based index).
125      * @param item the item (zero-based index).
126      *
127      * @return the z-value for the specified series and item.
128      */

129     public Number JavaDoc getZValue(int series, int item) {
130         return new Double JavaDoc(zVal[item]);
131     }
132
133 }
134
Popular Tags