KickJava   Java API By Example, From Geeks To Geeks.

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


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

48
49 package org.krysalis.jcharts.test;
50
51
52 import org.krysalis.jcharts.axisChart.AxisChart;
53 import org.krysalis.jcharts.chartData.*;
54 import org.krysalis.jcharts.properties.*;
55 import org.krysalis.jcharts.types.ChartType;
56
57 import java.awt.*;
58
59
60 /******************************************************************************************
61  * This file provides examples of how to create all the different chart types provided by
62  * this package.
63  *
64  *******************************************************************************************/

65 class LineTestDriver extends AxisChartTestBase
66 {
67     boolean supportsImageMap()
68     {
69         return true;
70     }
71
72
73     /******************************************************************************************
74      * Separate this so can use for combo chart test
75      *
76      * @param numberOfDataSets
77      ******************************************************************************************/

78     static ChartTypeProperties getChartTypeProperties( int numberOfDataSets )
79     {
80         Stroke[] strokes = new Stroke[ numberOfDataSets ];
81         for( int j = 0; j < numberOfDataSets; j++ )
82         {
83             strokes[ j ] = LineChartProperties.DEFAULT_LINE_STROKE;
84         }
85         strokes[ 0 ] = new BasicStroke( 3.0f );
86
87         Shape[] shapes = new Shape[ numberOfDataSets ];
88         for( int j = 0; j < numberOfDataSets; j++ )
89         {
90             shapes[ j ] = PointChartProperties.SHAPE_DIAMOND;
91         }
92         shapes[ 0 ] = PointChartProperties.SHAPE_CIRCLE;
93
94
95         return new LineChartProperties( strokes, shapes );
96     }
97
98
99     /******************************************************************************************
100      *
101      *
102      ******************************************************************************************/

103     DataSeries getDataSeries() throws ChartDataException
104     {
105         DataSeries dataSeries;
106         AxisChartDataSet axisChartDataSet;
107
108         int dataSize = (int) TestDataGenerator.getRandomNumber( 3, 3 );
109         int numberOfDataSets = ( int ) TestDataGenerator.getRandomNumber( 1, 1 );
110
111
112         dataSeries = super.createDataSeries( dataSize );
113
114         axisChartDataSet = super.createAxisChartDataSet( ChartType.LINE,
115                                                          getChartTypeProperties( numberOfDataSets ),
116                                                          numberOfDataSets,
117                                                          dataSize,
118                                                          10,
119                                                          5000 );
120
121         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
122
123         return dataSeries;
124     }
125
126
127
128     /******************************************************************************************
129      *
130      *
131      ******************************************************************************************
132      DataSeries getDataSeries() throws ChartDataException
133      {
134      String[] xAxisLabels={"1", "2", "3", "4", "5"};
135      DataSeries dataSeries=new DataSeries( xAxisLabels, "numbers", "numbers", "Bug #559177" );
136      AxisChartDataSet axisChartDataSet;
137
138      double[][] data={{1, 2, 3, 4, 5},
139      {7, 8, Double.NaN, Double.NaN, Double.NaN},
140      {Double.NaN, Double.NaN, Double.NaN, Double.NaN, 2}};
141
142      String[] legendLabels={"set 1", "set 2", "set 3"};
143      Paint[] paints={Color.blue, Color.red, Color.green};
144
145      axisChartDataSet=new AxisChartDataSet( data,
146      legendLabels,
147      paints,
148      ChartType.LINE,
149      this.getChartTypeProperties( 3 ) );
150
151      dataSeries.addIAxisPlotDataSet( axisChartDataSet );
152
153      return dataSeries;
154
155      }
156      */

157
158
159
160     public static void main( String JavaDoc[] args ) throws ChartDataException, PropertyException
161     {
162         LineChartProperties lineChartProperties= (LineChartProperties) getChartTypeProperties( 1 );
163         double[][] data= { { 280, 16, 150, 90 } };
164         Paint[] paints= { Color.blue };
165         String JavaDoc[] legendLabels= { "Test Legend Label" };
166         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties );
167
168         String JavaDoc[] axisLabels= null; //{ "1900", "1950", "2000", "2050" };
169
DataSeries dataSeries = new DataSeries( axisLabels, "X-Axis Title", "Y-Axis Title", "Chart Title" );
170         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
171
172
173         ChartProperties chartProperties= new ChartProperties();
174         AxisProperties axisProperties= new AxisProperties( false );
175         axisProperties.getYAxisProperties().setShowAxisLabels( false );
176         axisProperties.getXAxisProperties().setShowAxisLabels( false );
177
178         DataAxisProperties yAxis= (DataAxisProperties) axisProperties.getYAxisProperties();
179         yAxis.setUserDefinedScale( -10, 50 );
180       yAxis.setNumItems( 4 );
181         yAxis.setRoundToNearest( 1 );
182
183         LegendProperties legendProperties= new LegendProperties();
184
185         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
186
187         ChartTestDriver.exportImage( axisChart, "LineChartTest.png" );
188
189     }
190
191
192 }
193
Popular Tags