KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: PointTestDriver.java,v 1.2 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.chartData.interfaces.IAxisDataSeries;
54 import org.krysalis.jcharts.properties.*;
55 import org.krysalis.jcharts.types.ChartType;
56 import org.krysalis.jcharts.axisChart.AxisChart;
57
58 import java.awt.*;
59
60
61 /******************************************************************************************
62  * This file provides examples of how to create all the different chart types provided by
63  * this package.
64  *
65  *******************************************************************************************/

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

78     static ChartTypeProperties getChartTypeProperties( int numberOfDataSets )
79     {
80         //Shape rectangle= new Rectangle2D.Double( 0, 0, 8, 8 );
81
Shape[] shapes={PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE};
82         boolean[] fillPointFlags={true, true};
83         Paint[] outlinePaints={Color.black, Color.blue};
84
85         return new PointChartProperties( shapes, fillPointFlags, outlinePaints );
86     }
87
88
89     /*********************************************************************************************************
90      *
91      *
92      *********************************************************************************************************/

93     DataSeries getDataSeries() throws ChartDataException
94     {
95         int dataSize=(int) TestDataGenerator.getRandomNumber( 13, 15 );
96         int numberOfDataSets=2; //(int) TestDataGenerator.getRandomNumber( 1, 3 );
97

98
99         DataSeries dataSeries=super.createDataSeries( dataSize );
100
101
102         AxisChartDataSet axisChartDataSet=super.createAxisChartDataSet( ChartType.POINT,
103                                                                                              getChartTypeProperties( numberOfDataSets ),
104                                                                                              numberOfDataSets,
105                                                                                              dataSize,
106                                                                                              0,
107                                                                                              5000 );
108
109         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
110
111         return dataSeries;
112     }
113
114
115
116     /*****************************************************************************************
117      *
118      * @param args
119      * @throws PropertyException
120      * @throws ChartDataException
121      *****************************************************************************************/

122     public static void main( String JavaDoc[] args ) throws PropertyException, ChartDataException
123     {
124         Shape[] shapes={PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE};
125         boolean[] fillPointFlags={true, true};
126         Paint[] outlinePaints={Color.black, Color.blue};
127         PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints );
128
129
130         //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
131
//clusteredBarChartProperties.addPreRenderEventListener( backgroundRenderer );
132

133 /*
134
135         ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, true, -1 );
136         valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
137         valueLabelRenderer.useVerticalLabels( false );
138         clusteredBarChartProperties.addPostRenderEventListener( valueLabelRenderer );
139 */

140
141
142
143         double[][] data = {{280, 16, 150, 90, 60, 200, 150, 60 }, {80, 216, 10, 30, 15, 90, 150, 87 } };
144         Paint[] paints = {Color.yellow, Color.blue };
145         String JavaDoc[] legendLabels = {"Test Legend Label", "second set"};
146         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties );
147
148         String JavaDoc[] axisLabels = {"1900", "1950", "2000", "2050", "3000", "3050", "4000", "4050" };
149         IAxisDataSeries dataSeries = new DataSeries( axisLabels, "Cookies", "Years", null );
150         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
151
152
153         ChartProperties chartProperties = new ChartProperties();
154         AxisProperties axisProperties = new AxisProperties( false );
155
156
157         //axisProperties.getXAxisProperties().setShowAxisLabels( false );
158
//axisProperties.getYAxisProperties().setShowAxisLabels( false );
159
//axisProperties.getYAxisProperties().setShowTicks( AxisTypeProperties.TICKS_NONE );
160

161         //axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_NONE );
162
//axisProperties.getYAxisProperties().setAxisStroke( new ChartStroke( new BasicStroke( 1.5f ), Color.red ) );
163

164 /*
165
166         DataAxisProperties xAxis = (DataAxisProperties) axisProperties.getXAxisProperties();
167         xAxis.setRoundToNearest( 1 );
168         xAxis.setUserDefinedScale( -300, 200 );
169 */

170
171         LegendProperties legendProperties = new LegendProperties();
172
173         AxisChart axisChart = new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
174
175         axisChart.renderWithImageMap();
176
177         ChartTestDriver.exportImage( axisChart, "pointChartTest.png" );
178     }
179
180 }
181
Popular Tags