KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > test > ScatterPlotTestDriver


1 /***********************************************************************************************
2  * File Info: $Id: ScatterPlotTestDriver.java,v 1.3 2003/08/08 08:51:27 nicolaken 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.test;
41
42
43 import java.awt.BasicStroke JavaDoc;
44 import java.awt.Paint JavaDoc;
45 import java.awt.Shape JavaDoc;
46 import java.awt.Stroke JavaDoc;
47 import java.awt.geom.Point2D JavaDoc;
48
49 import org.krysalis.jcharts.axisChart.ScatterPlotAxisChart;
50 import org.krysalis.jcharts.chartData.ChartDataException;
51 import org.krysalis.jcharts.chartData.DataSeries;
52 import org.krysalis.jcharts.chartData.ScatterPlotDataSeries;
53 import org.krysalis.jcharts.chartData.ScatterPlotDataSet;
54 import org.krysalis.jcharts.properties.AxisProperties;
55 import org.krysalis.jcharts.properties.ChartProperties;
56 import org.krysalis.jcharts.properties.DataAxisProperties;
57 import org.krysalis.jcharts.properties.LegendProperties;
58 import org.krysalis.jcharts.properties.LineChartProperties;
59 import org.krysalis.jcharts.properties.PointChartProperties;
60 import org.krysalis.jcharts.properties.PropertyException;
61 import org.krysalis.jcharts.properties.ScatterPlotProperties;
62
63
64 /******************************************************************************************
65  * This file provides examples of how to create all the different chart types provided by
66  * this package.
67  *
68  *******************************************************************************************/

69 public class ScatterPlotTestDriver extends AxisChartTestBase
70 {
71     boolean supportsImageMap()
72     {
73         return true;
74     }
75
76
77     /******************************************************************************************
78      * Separate this so can use for combo chart test
79      *
80      * @param numberOfDataSets
81      ******************************************************************************************/

82     private ScatterPlotProperties getScatterPlotProperties( int numberOfDataSets )
83     {
84         Stroke JavaDoc[] strokes = new Stroke JavaDoc[ numberOfDataSets ];
85         for( int j = 0; j < numberOfDataSets; j++ )
86         {
87             strokes[ j ] = LineChartProperties.DEFAULT_LINE_STROKE;
88         }
89         strokes[ 0 ] = new BasicStroke JavaDoc( 3.0f );
90
91         Shape JavaDoc[] shapes = new Shape JavaDoc[ numberOfDataSets ];
92         for( int j = 0; j < numberOfDataSets; j++ )
93         {
94             shapes[ j ] = PointChartProperties.SHAPE_DIAMOND;
95         }
96         shapes[ 0 ] = PointChartProperties.SHAPE_CIRCLE;
97
98
99         return new ScatterPlotProperties( strokes, shapes );
100     }
101
102
103     /*****************************************************************************************
104      * Generates a random MultiDataSet
105      *
106      * @param numberOfDataSets
107      * @param numberOfValuesToCreate the number of doubles to generate
108      * @param xMinValue
109      * @param xMaxValue
110      * @param yMinValue
111      * @param yMaxValue
112      * @return AxisChartDataSet
113      ******************************************************************************************/

114     private ScatterPlotDataSet createScatterPlotDataSet( int numberOfDataSets,
115                                                                           int numberOfValuesToCreate,
116                                                                           int xMinValue,
117                                                                           int xMaxValue,
118                                                                           int yMinValue,
119                                                                           int yMaxValue ) throws ChartDataException
120     {
121         //Point2D.Double[] points= TestDataGenerator.getRandomPoints( numberOfValuesToCreate, xMinValue, xMaxValue, yMinValue, yMaxValue );
122

123
124         Point2D.Double JavaDoc[] points= new Point2D.Double JavaDoc[ 20 ];
125         for( int x = 0; x < 20; x++ )
126         {
127             //--- y = x^2
128
points[ x ]= new Point2D.Double JavaDoc();
129             points[ x ].setLocation( x, Math.pow( x, 2 ) );
130         }
131
132         String JavaDoc[] legendLabels = TestDataGenerator.getRandomStrings( 1, 12, false );
133 // Paint[] paints = TestDataGenerator.getRandomPaints( numberOfDataSets );
134
Paint JavaDoc paint = TestDataGenerator.getRandomPaint();
135
136         ScatterPlotDataSet scatterPlotDataSet= new ScatterPlotDataSet( this.getScatterPlotProperties( 1 ) );
137       scatterPlotDataSet.addDataPoints( points, paint, legendLabels[ 0 ] );
138
139 System.out.println( "legendLabels[ 0 ]= " + legendLabels[ 0 ] );
140         return scatterPlotDataSet;
141     }
142
143
144     /******************************************************************************************
145      *
146      *
147      ******************************************************************************************/

148     DataSeries getDataSeries() throws ChartDataException
149     {
150         DataSeries dataSeries= null;
151
152         int dataSize = (int) TestDataGenerator.getRandomNumber( 3, 3 );
153         int numberOfDataSets = (int) TestDataGenerator.getRandomNumber( 1, 1 );
154
155         //ScatterPlotDataSet scatterPlotDataSet= this.createScatterPlotDataSet( )
156

157         //String[] xAxisLabels = TestDataGenerator.getRandomStrings( numberOfValuesToCreate, ( int ) TestDataGenerator.getRandomNumber( 10 ), false );
158
String JavaDoc xAxisTitle = TestDataGenerator.getRandomString( 15, true );
159         String JavaDoc yAxisTitle = TestDataGenerator.getRandomString( 15, true );
160         //dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, "This is a test title that is so freaking long is is going to wrap around the image for sure. lfksjg;ljs; dflgkjdfgsdgdg dsgdsgsdfg dsfgsdfgsdfgs dfgdsfgd" );
161

162
163         //dataSeries.addIAxisPlotDataSet( axisChartDataSet );
164

165         return dataSeries;
166     }
167
168
169     /******************************************************************************************
170      *
171      *
172      ******************************************************************************************
173      DataSeries getDataSeries() throws ChartDataException
174      {
175      String[] xAxisLabels={"1", "2", "3", "4", "5"};
176      DataSeries dataSeries=new DataSeries( xAxisLabels, "numbers", "numbers", "Bug #559177" );
177      AxisChartDataSet axisChartDataSet;
178
179      double[][] data={{1, 2, 3, 4, 5},
180      {7, 8, Double.NaN, Double.NaN, Double.NaN},
181      {Double.NaN, Double.NaN, Double.NaN, Double.NaN, 2}};
182
183      String[] legendLabels={"set 1", "set 2", "set 3"};
184      Paint[] paints={Color.blue, Color.red, Color.green};
185
186      axisChartDataSet=new AxisChartDataSet( data,
187      legendLabels,
188      paints,
189      ChartType.LINE,
190      this.getChartTypeProperties( 3 ) );
191
192      dataSeries.addIAxisPlotDataSet( axisChartDataSet );
193
194      return dataSeries;
195
196      }
197      */

198
199
200     public static void main( String JavaDoc[] args ) throws ChartDataException, PropertyException
201     {
202       ScatterPlotTestDriver s= new ScatterPlotTestDriver();
203
204       ScatterPlotDataSet scatterPlotDataSet= s.createScatterPlotDataSet( 1, 5, -1000, 3000, 200, 500 );
205         ScatterPlotDataSeries scatterPlotDataSeries = new ScatterPlotDataSeries( scatterPlotDataSet,
206                                                                                                          "X-Axis Title",
207                                                                                                          "Y-Axis Title",
208                                                                                                          "Chart Title" );
209
210         DataAxisProperties xAxisProperties= new DataAxisProperties();
211         xAxisProperties.setUserDefinedScale( -5, 3 );
212         xAxisProperties.setNumItems( 10 );
213         xAxisProperties.setRoundToNearest( 0 );
214
215         DataAxisProperties yAxisProperties= new DataAxisProperties();
216         yAxisProperties.setUserDefinedScale( -30, 50 );
217         yAxisProperties.setNumItems( 10 );
218         yAxisProperties.setRoundToNearest( 1 );
219
220         AxisProperties axisProperties = new AxisProperties( xAxisProperties, yAxisProperties );
221       ChartProperties chartProperties = new ChartProperties();
222         LegendProperties legendProperties = new LegendProperties();
223
224         ScatterPlotAxisChart scatterPlotAxisChart = new ScatterPlotAxisChart( scatterPlotDataSeries,
225                                                                                                      chartProperties,
226                                                                                                      axisProperties,
227                                                                                                      legendProperties,
228                                                                                                      500,
229                                                                                                      400 );
230
231         ChartTestDriver.exportImage( scatterPlotAxisChart, "ScatterPlotTest.png" );
232     }
233
234
235 }
236
Popular Tags