KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > chartData > DataSeries


1 /***********************************************************************************************
2  * File Info: $Id: DataSeries.java,v 1.1 2003/05/17 16:58:11 nathaniel_auvil Exp $
3  * Copyright (C) 2002
4  * Author: Nathaniel G. Auvil
5  * Contributor(s):
6  *
7  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
8  *
9  * Redistribution and use of this software and associated documentation ("Software"), with or
10  * without modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain copyright statements and notices.
13  * Redistributions must also contain a copy of this document.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
16  * conditions and the following disclaimer in the documentation and/or other materials
17  * provided with the distribution.
18  *
19  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
20  * products derived from this Software without prior written permission of Nathaniel G.
21  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
22  *
23  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
24  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
25  * registered trademark of Nathaniel G. Auvil.
26  *
27  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
28  *
29  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
30  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
36  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
37  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  ************************************************************************************************/

39
40 package org.krysalis.jcharts.chartData;
41
42
43 import org.krysalis.jcharts.chartData.interfaces.IDataSeries;
44 import org.krysalis.jcharts.properties.PropertyException;
45 import org.krysalis.jcharts.test.HTMLGenerator;
46 import org.krysalis.jcharts.test.HTMLTestable;
47
48 import java.util.Iterator JavaDoc;
49
50
51 /*********************************************************************************************
52  * Collection of all IAxisPlotDataSets to display in an AxisChart
53  *
54  **********************************************************************************************/

55 public class DataSeries extends AxisDataSeries implements IDataSeries, HTMLTestable
56 {
57     private String JavaDoc[] axisLabels;
58
59
60     /******************************************************************************************
61      * Constructor
62      *
63      * @param axisLabels
64      * @param xAxisTitle if this is NULL, no title will be displayed
65      * @param yAxisTitle if this is NULL, no title will be displayed
66      * @param chartTitle if this is NULL, no title will be displayed
67      *******************************************************************************************/

68     public DataSeries( String JavaDoc[] axisLabels, String JavaDoc xAxisTitle, String JavaDoc yAxisTitle, String JavaDoc chartTitle )
69     {
70         super( xAxisTitle, yAxisTitle, chartTitle );
71
72         this.axisLabels = axisLabels;
73     }
74
75
76     /******************************************************************************************
77      * Returns the x-axis label corresponding to the passed index
78      *
79      * @param index
80      * @return String
81      *******************************************************************************************/

82     public String JavaDoc getAxisLabel( int index )
83     {
84         return this.axisLabels[ index ];
85     }
86
87
88     /******************************************************************************************
89      * Returns the number of labels on the x-axis
90      *
91      * @return int
92      ******************************************************************************************/

93     public int getNumberOfAxisLabels()
94     {
95         if( this.axisLabels != null )
96         {
97             return this.axisLabels.length;
98         }
99         else
100         {
101             return 0;
102         }
103     }
104
105
106     /****************************************************************************************
107      *
108      * @throws ChartDataException
109      * @throws PropertyException
110      ***************************************************************************************/

111     public void validate() throws ChartDataException, PropertyException
112     {
113         super.validate();
114
115         if( this.axisLabels != null && this.axisLabels.length != super.getSizeOfEachDataSet() )
116         {
117             throw new ChartDataException( "The size of the Axis Labels Array does not match the number of data elements to be plotted." );
118         }
119     }
120
121
122     /*********************************************************************************************
123      * Enables the testing routines to display the contents of this Object.
124      *
125      * @param htmlGenerator
126      **********************************************************************************************/

127     public void toHTML( HTMLGenerator htmlGenerator )
128     {
129         htmlGenerator.propertiesTableRowStart();
130         {
131             htmlGenerator.propertiesTableStart( this.getClass().getName() );
132             htmlGenerator.addTableRow( "xAxisLabels", HTMLGenerator.arrayToString( this.axisLabels ) );
133             htmlGenerator.addTableRow( "totalNumberOfDataSets", Integer.toString( totalNumberOfDataSets ) );
134             htmlGenerator.propertiesTableEnd();
135         }
136         htmlGenerator.propertiesTableRowEnd();
137
138
139         htmlGenerator.propertiesTableRowStart();
140         {
141             //---loop the data sets
142
Iterator JavaDoc iterator = this.getIAxisPlotDataSetIterator();
143             Object JavaDoc object;
144             while( iterator.hasNext() )
145             {
146                 object = iterator.next();
147                 if( object instanceof HTMLTestable )
148                 {
149                     ((HTMLTestable) object).toHTML( htmlGenerator );
150                 }
151             }
152         }
153         htmlGenerator.propertiesTableRowEnd();
154     }
155 }
156
Popular Tags