KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: AreaTestDriver.java,v 1.3 2004/05/31 16:25:42 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.chartData.*;
53 import org.krysalis.jcharts.properties.*;
54 import org.krysalis.jcharts.types.ChartType;
55 import org.krysalis.jcharts.axisChart.AxisChart;
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 public class AreaTestDriver extends AxisChartTestBase
66 {
67
68    boolean supportsImageMap()
69     {
70         return false;
71     }
72
73
74     /******************************************************************************************
75      * Separate this so can use for combo chart test
76      *
77      ******************************************************************************************/

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

95
96         return new AreaChartProperties();
97     }
98
99
100     /******************************************************************************************
101      *
102      *
103      ******************************************************************************************/

104     DataSeries getDataSeries() throws ChartDataException
105     {
106         DataSeries dataSeries;
107         AxisChartDataSet axisChartDataSet;
108
109         int dataSize=(int) TestDataGenerator.getRandomNumber( 10, 50 );
110         int numberOfDataSets=(int) TestDataGenerator.getRandomNumber( 1, 3 );
111
112
113         dataSeries=super.createDataSeries( dataSize );
114
115
116         ChartType chartType=null;
117         if( TestDataGenerator.getRandomNumber( 1.0d ) > 0.5 )
118         {
119             chartType=ChartType.AREA;
120         }
121         else
122         {
123             chartType=ChartType.AREA_STACKED;
124         }
125
126
127         axisChartDataSet=super.createAxisChartDataSet( chartType,
128                                                                       getChartTypeProperties( numberOfDataSets ),
129                                                                       numberOfDataSets,
130                                                                       dataSize,
131                                                                       0,
132                                                                       5000 );
133
134         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
135
136         return dataSeries;
137     }
138
139
140
141     public static void main( String JavaDoc[] args ) throws ChartDataException, PropertyException
142     {
143
144         //StackedAreaChartProperties stacked= new StackedAreaChartProperties();
145
AreaChartProperties areaChartProperties= new AreaChartProperties();
146
147         double[][] data= { { 10, 15, 30 }, {30, 30, 10}, {20, 25, 20} };
148         Paint[] paints= { new Color( 0, 255, 0, 100 ), new Color( 255, 0, 0, 100 ), new Color( 0, 0, 255, 100 ) };
149         String JavaDoc[] legendLabels= { "Legend Label", "Legend Label", "Legend Label" };
150         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.AREA, areaChartProperties );
151
152         String JavaDoc[] axisLabels= { "1", "2", "3" };
153         DataSeries dataSeries = new DataSeries( axisLabels, "X-Axis Title", "Y-Axis Title", "Chart Title" );
154         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
155
156
157         ChartProperties chartProperties= new ChartProperties();
158         chartProperties.setEdgePadding( 50 );
159
160         AxisProperties axisProperties= new AxisProperties( false );
161
162       DataAxisProperties dataAxisProperties= (DataAxisProperties) axisProperties.getYAxisProperties();
163         dataAxisProperties.setNumItems( 4 );
164         dataAxisProperties.setRoundToNearest( 1 );
165
166         LegendProperties legendProperties= new LegendProperties();
167
168         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
169
170         ChartTestDriver.exportImage( axisChart, "AreaChartTest.png" );
171
172     }
173
174 }
175
Popular Tags