KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: BarTestDriver.java,v 1.5 2004/05/27 02:06:39 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 java.awt.BasicStroke JavaDoc;
53 import java.awt.Color JavaDoc;
54 import java.awt.Paint JavaDoc;
55
56 import org.krysalis.jcharts.axisChart.AxisChart;
57 import org.krysalis.jcharts.chartData.AxisChartDataSet;
58 import org.krysalis.jcharts.chartData.ChartDataException;
59 import org.krysalis.jcharts.chartData.DataSeries;
60 import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
61 import org.krysalis.jcharts.properties.AxisProperties;
62 import org.krysalis.jcharts.properties.AxisTypeProperties;
63 import org.krysalis.jcharts.properties.BarChartProperties;
64 import org.krysalis.jcharts.properties.ChartProperties;
65 import org.krysalis.jcharts.properties.ChartTypeProperties;
66 import org.krysalis.jcharts.properties.DataAxisProperties;
67 import org.krysalis.jcharts.properties.LegendProperties;
68 import org.krysalis.jcharts.properties.PropertyException;
69 import org.krysalis.jcharts.properties.util.ChartStroke;
70 import org.krysalis.jcharts.types.ChartType;
71
72
73 /******************************************************************************************
74  * This file provides examples of how to create all the different chart types provided by
75  * this package.
76  *
77  *******************************************************************************************/

78 public final class BarTestDriver extends AxisChartTestBase
79 {
80     boolean supportsImageMap()
81     {
82         return true;
83     }
84
85
86     /******************************************************************************************
87      * Separate this so can use for combo chart test
88      *
89      ******************************************************************************************/

90     static ChartTypeProperties getChartTypeProperties( int numberOfDataSets )
91     {
92         BarChartProperties barChartProperties = new BarChartProperties();
93         barChartProperties.setWidthPercentage( 1f );
94
95         return barChartProperties;
96     }
97
98
99     /******************************************************************************************
100      *
101      *
102      ******************************************************************************************/

103     DataSeries getDataSeries() throws ChartDataException
104     {
105         int dataSize = (int) TestDataGenerator.getRandomNumber( 2, 25 );
106         int numberOfDataSets = 1; //(int) TestDataGenerator.getRandomNumber( 1, 3 );
107

108
109         AxisChartDataSet axisChartDataSet;
110
111
112         DataSeries dataSeries = super.createDataSeries( dataSize );
113
114         axisChartDataSet = super.createAxisChartDataSet( ChartType.BAR,
115                                                                          getChartTypeProperties( numberOfDataSets ),
116                                                                          numberOfDataSets,
117                                                                          dataSize,
118                                                                          -200,
119                                                                          400 );
120
121         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
122
123         return dataSeries;
124     }
125
126
127     /*****************************************************************************************
128      *
129      * @param args
130      * @throws PropertyException
131      * @throws ChartDataException
132      *****************************************************************************************/

133     public static void main( String JavaDoc[] args ) throws PropertyException, ChartDataException
134     {
135         BarChartProperties barChartProperties = new BarChartProperties();
136
137         //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
138
//barChartProperties.addPreRenderEventListener( backgroundRenderer );
139

140 /*
141         ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, true, -1 );
142         valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
143         valueLabelRenderer.useVerticalLabels( false );
144         barChartProperties.addPostRenderEventListener( valueLabelRenderer );
145 */

146
147
148
149
150
151         double[][] data = {{.40, .60, .04, .3 }};
152         Paint JavaDoc[] paints = {Color.green};
153         String JavaDoc[] legendLabels = {"Test Legend Label"};
154         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR, barChartProperties );
155
156         String JavaDoc[] axisLabels = {"1900", "2000", "2010", "2050" };
157         //String[] axisLabels = {"1900", "1910", "1920", "1930", "1940", "1950", "1960", "1970", "1980", "1990", "2000" };
158
IAxisDataSeries dataSeries = new DataSeries( axisLabels, "Wonka Bars", "Years", "Oompa Loompa Productivity" );
159         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
160
161
162         ChartProperties chartProperties = new ChartProperties();
163         AxisProperties axisProperties = new AxisProperties( false );
164
165         axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_ALL );
166         axisProperties.getYAxisProperties().setAxisStroke( new ChartStroke( new BasicStroke JavaDoc( 1.5f ), Color.red ) );
167       axisProperties.getYAxisProperties().setGridLineChartStroke( new ChartStroke( new BasicStroke JavaDoc( 1.5f ), Color.red ) );
168
169         //axisProperties.setXAxisLabelsAreVertical( true );
170

171
172         DataAxisProperties yAxis = (DataAxisProperties) axisProperties.getYAxisProperties();
173 // yAxis.setUsePercentSigns( true );
174
// yAxis.setUserDefinedScale( 0, 0.05 );
175
yAxis.setNumItems( 10 );
176         yAxis.setRoundToNearest( -3 );
177
178
179
180         LegendProperties legendProperties = new LegendProperties();
181
182         AxisChart axisChart = new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
183
184         ChartTestDriver.exportImage( axisChart, "BarChartTest.png" );
185
186
187     }
188
189 }
190
Popular Tags