KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.krysalis.jcharts.chartData;
2
3
4 import java.awt.Paint JavaDoc;
5
6 import org.krysalis.jcharts.chartData.interfaces.IRadarChartDataSet;
7 import org.krysalis.jcharts.properties.RadarChartProperties;
8 import org.krysalis.jcharts.test.HTMLGenerator;
9
10
11 /**
12  * The chart dataset of a radar chart
13  *
14  * @author Rami Hansenne
15  */

16 final public class RadarChartDataSet extends DataSet implements IRadarChartDataSet
17 {
18         private String JavaDoc chartTitle;
19         private String JavaDoc[] axisLabels;
20
21         /******************************************************************************************
22          * Constructor
23          *
24          * @param chartTitle if the title is NULL, no title will be drawn
25          * @param data the data sets to be displayed in the chart.
26          * @param legendLabels if this is: NULL there will be no Legend. Otherwise, there must be an
27          * one to one mapping of labels to data sets.
28          * @param paints paints to use for the data sets. There must be an one to one mapping of
29          * labels to data sets.
30          * @param axisLabels
31          * @param chartTypeProperties properties Object specific to the type of chart you are rendering.
32          * @throws ChartDataException if data is not in correct form.
33          *******************************************************************************************/

34         public RadarChartDataSet( String JavaDoc chartTitle,
35                                   double[][] data,
36                                   String JavaDoc[] legendLabels,
37                                   Paint JavaDoc[] paints,
38                                   String JavaDoc[] axisLabels,
39                                   RadarChartProperties chartTypeProperties ) throws ChartDataException
40         {
41                 super( data, legendLabels, paints, chartTypeProperties );
42                 validateData(data,legendLabels,axisLabels,paints);
43                 this.chartTitle = chartTitle;
44                 this.axisLabels = axisLabels;
45         }
46
47
48
49         /*******************************************************************************************
50          * Perform some limited validation of the structure of the passed data. This is useful for
51          * development.
52          *
53          * @param data
54          * @param legendLabels
55          * @param axisLabels
56          * @param paints
57          * @throws ChartDataException
58          *******************************************************************************************/

59         private void validateData( double[][] data, String JavaDoc[] legendLabels, String JavaDoc[] axisLabels, Paint JavaDoc[] paints ) throws ChartDataException
60         {
61                 if( legendLabels != null && ( data.length != legendLabels.length ) )
62                 {
63                         throw new ChartDataException( "There is not an one to one mapping of 'legend labels' to 'data items'." );
64                 }
65
66                 if( data.length != paints.length )
67                 {
68                         throw new ChartDataException( "There is not an one to one mapping of 'Paint' Implementations to 'data items'." );
69                 }
70
71                 for (int i=1;i<data.length;i++)
72                     if (data[i].length!=data[0].length)
73                       throw new ChartDataException( "All data items should contain an equal number of values." );
74
75                 if (data.length>0 && axisLabels.length!=data[0].length)
76                   throw new ChartDataException( "There is not a one to one mapping of axis labels to values per 'data item'." );
77
78         }
79
80
81         /******************************************************************************************
82          * Returns the chart title.
83          *
84          * @return String the chart title. If this returns NULL, no title will be displayed.
85          ******************************************************************************************/

86         public String JavaDoc getChartTitle()
87         {
88                 return this.chartTitle;
89         }
90
91
92
93         /******************************************************************************************
94          * Returns the value in the data set at the specified position.
95          *
96          * @param dataset
97          * @param index
98          * @return double
99          * @throws ArrayIndexOutOfBoundsException
100          *******************************************************************************************/

101         public final double getValue( int dataset, int index ) throws ArrayIndexOutOfBoundsException JavaDoc
102         {
103                 return super.data[ dataset ][ index ];
104         }
105
106
107         /******************************************************************************************
108          * Returns the number of data sets
109          *
110          * @return int
111          ******************************************************************************************/

112         public final int getNumberOfDataSets()
113         {
114                 return this.data.length;
115         }
116
117         /******************************************************************************************
118          * Returns the number of values per data set
119          *
120          * @return int
121          ******************************************************************************************/

122         public final int getDataSetSize()
123         {
124                if (data.length==0)
125                  return 0;
126                else return data[0].length;
127         }
128
129         /******************************************************************************************
130          * Returns the x-axis label corresponding to the passed index
131          *
132          * @param index
133          * @return String
134          *******************************************************************************************/

135         public String JavaDoc getAxisLabel( int index )
136         {
137                 return this.axisLabels[ index ];
138         }
139
140
141         /******************************************************************************************
142          * Returns the number of labels on the x-axis
143          *
144          * @return int
145          ******************************************************************************************/

146         public int getNumberOfAxisLabels()
147         {
148                 if( this.axisLabels != null )
149                 {
150                         return this.axisLabels.length;
151                 }
152                 else
153                 {
154                         return 0;
155                 }
156         }
157
158         /*********************************************************************************************
159          * Enables the testing routines to display the contents of this Object.
160          *
161          * @param htmlGenerator
162          **********************************************************************************************/

163         public void toHTML( HTMLGenerator htmlGenerator )
164         {
165                 super.toHTML( htmlGenerator );
166         }
167
168 }
169
Popular Tags