KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 package org.krysalis.jcharts.test;
36
37
38 import java.awt.Color JavaDoc;
39 import java.awt.Paint JavaDoc;
40
41 import org.krysalis.jcharts.axisChart.AxisChart;
42 import org.krysalis.jcharts.chartData.AxisChartDataSet;
43 import org.krysalis.jcharts.chartData.ChartDataException;
44 import org.krysalis.jcharts.chartData.DataSeries;
45 import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
46 import org.krysalis.jcharts.properties.AxisProperties;
47 import org.krysalis.jcharts.properties.ChartProperties;
48 import org.krysalis.jcharts.properties.LegendProperties;
49 import org.krysalis.jcharts.properties.PropertyException;
50 import org.krysalis.jcharts.properties.StackedBarChartProperties;
51 import org.krysalis.jcharts.types.ChartType;
52
53
54 /******************************************************************************************
55  * This file provides examples of how to create all the different chart types provided by
56  * this package.
57  *
58  * @author Nathaniel Auvil
59  * @version $Id: StackedBarTestDriver.java,v 1.3 2003/08/08 08:51:27 nicolaken Exp $
60  *******************************************************************************************/

61 public class StackedBarTestDriver extends AxisChartTestBase
62 {
63     boolean supportsImageMap()
64     {
65         return true;
66     }
67
68
69     /******************************************************************************************
70      *
71      *
72      ******************************************************************************************/

73     DataSeries getDataSeries() throws ChartDataException
74     {
75         StackedBarChartProperties stackedBarChartProperties;
76         DataSeries dataSeries;
77         AxisChartDataSet axisChartDataSet;
78
79         int dataSize=(int) TestDataGenerator.getRandomNumber( 1, 30 );
80         int numberOfDataSets=(int) TestDataGenerator.getRandomNumber( 1, 5 );
81
82
83         dataSeries=super.createDataSeries( dataSize );
84
85
86         stackedBarChartProperties=new StackedBarChartProperties();
87
88
89         axisChartDataSet=super.createAxisChartDataSet( ChartType.BAR_STACKED,
90                                                                       stackedBarChartProperties,
91                                                                       numberOfDataSets,
92                                                                       dataSize,
93                                                                       0,
94                                                                       5000 );
95
96         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
97
98         return dataSeries;
99     }
100
101
102     /*****************************************************************************************
103      *
104      * @param args
105      * @throws PropertyException
106      * @throws ChartDataException
107      *****************************************************************************************/

108     public static void main( String JavaDoc[] args ) throws PropertyException, ChartDataException
109     {
110         StackedBarChartProperties stackedBarChartProperties = new StackedBarChartProperties();
111
112         //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
113
//clusteredBarChartProperties.addPreRenderEventListener( backgroundRenderer );
114

115 /*
116
117         ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, true, -1 );
118         valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
119         valueLabelRenderer.useVerticalLabels( false );
120         clusteredBarChartProperties.addPostRenderEventListener( valueLabelRenderer );
121 */

122
123
124
125         double[][] data = {{280, 16, 150, 90, 60, 200, 150, 60 }, {80, 216, 10, 30, 15, 90, 150, 87 } };
126         Paint JavaDoc[] paints = {Color.yellow, Color.blue };
127         String JavaDoc[] legendLabels = {"Test Legend Label", "second set"};
128         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR_STACKED, stackedBarChartProperties );
129
130         String JavaDoc[] axisLabels = {"1900", "1950", "2000", "2050", "3000", "3050", "4000", "4050" };
131         IAxisDataSeries dataSeries = new DataSeries( axisLabels, "Cookies", "Years", null );
132         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
133
134
135         ChartProperties chartProperties = new ChartProperties();
136         AxisProperties axisProperties = new AxisProperties( false );
137
138
139         //axisProperties.getXAxisProperties().setShowAxisLabels( false );
140
//axisProperties.getYAxisProperties().setShowAxisLabels( false );
141
//axisProperties.getYAxisProperties().setShowTicks( AxisTypeProperties.TICKS_NONE );
142

143         //axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_NONE );
144
//axisProperties.getYAxisProperties().setAxisStroke( new ChartStroke( new BasicStroke( 1.5f ), Color.red ) );
145

146 /*
147
148         DataAxisProperties xAxis = (DataAxisProperties) axisProperties.getXAxisProperties();
149         xAxis.setRoundToNearest( 1 );
150         xAxis.setUserDefinedScale( -300, 200 );
151 */

152
153         LegendProperties legendProperties = new LegendProperties();
154
155         AxisChart axisChart = new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
156
157         axisChart.renderWithImageMap();
158
159         ChartTestDriver.exportImage( axisChart, "StackedBarChartTest.png" );
160     }
161
162 }
163
Popular Tags