KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: ClusteredBarTestDriver.java,v 1.2 2003/12/07 14:03:51 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
50 package org.krysalis.jcharts.test;
51
52
53 import org.krysalis.jcharts.chartData.*;
54 import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
55 import org.krysalis.jcharts.properties.*;
56 import org.krysalis.jcharts.properties.util.ChartStroke;
57 import org.krysalis.jcharts.types.ChartType;
58 import org.krysalis.jcharts.axisChart.customRenderers.axisValue.renderers.*;
59 import org.krysalis.jcharts.axisChart.AxisChart;
60
61 import java.awt.*;
62
63
64 /******************************************************************************************
65  * This file provides examples of how to create all the different chart types provided by
66  * this package.
67  *
68  *******************************************************************************************/

69 public class ClusteredBarTestDriver extends AxisChartTestBase
70 {
71     boolean supportsImageMap()
72     {
73         return true;
74     }
75
76
77     /******************************************************************************************
78      *
79      *
80      ******************************************************************************************/

81     DataSeries getDataSeries() throws ChartDataException
82     {
83         ClusteredBarChartProperties clusteredBarChartProperties;
84         DataSeries dataSeries;
85         AxisChartDataSet axisChartDataSet;
86
87         int dataSize = ( int ) TestDataGenerator.getRandomNumber( 1, 10 );
88         int numberOfDataSets = ( int ) TestDataGenerator.getRandomNumber( 1, 4 );
89
90
91         dataSeries = super.createDataSeries( dataSize );
92
93
94         clusteredBarChartProperties = new ClusteredBarChartProperties();
95
96
97         axisChartDataSet = super.createAxisChartDataSet( ChartType.BAR_CLUSTERED,
98                                                                          clusteredBarChartProperties,
99                                                                          numberOfDataSets,
100                                                                          dataSize,
101                                                                          -5000,
102                                                                          5000 );
103
104         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
105
106         return dataSeries;
107     }
108
109
110
111
112     /*****************************************************************************************
113      *
114      * @param args
115      * @throws PropertyException
116      * @throws ChartDataException
117      *****************************************************************************************/

118     public static void main( String JavaDoc[] args ) throws PropertyException, ChartDataException
119     {
120         ClusteredBarChartProperties clusteredBarChartProperties = new ClusteredBarChartProperties();
121
122         //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
123
//clusteredBarChartProperties.addPreRenderEventListener( backgroundRenderer );
124

125         ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, false, false, 0 );
126         valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
127         valueLabelRenderer.useVerticalLabels( false );
128         clusteredBarChartProperties.addPostRenderEventListener( valueLabelRenderer );
129
130
131
132         double[][] data = {{280, 0, -150, 90}, {80, 216, -10, 30} };
133         Paint[] paints = {Color.yellow, Color.blue };
134         String JavaDoc[] legendLabels = {"Test Legend Label", "other data"};
135         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR_CLUSTERED, clusteredBarChartProperties );
136
137         String JavaDoc[] axisLabels = {"1900", "1950", "2000", "2050"};
138         IAxisDataSeries dataSeries = new DataSeries( axisLabels, "Cookies", "Years", null );
139         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
140
141
142         ChartProperties chartProperties = new ChartProperties();
143         AxisProperties axisProperties = new AxisProperties( false );
144
145         axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_NONE );
146         axisProperties.getYAxisProperties().setAxisStroke( new ChartStroke( new BasicStroke( 1.5f ), Color.red ) );
147
148
149         DataAxisProperties yAxis = (DataAxisProperties) axisProperties.getYAxisProperties();
150         yAxis.setRoundToNearest( 1 );
151         //xAxis.setUserDefinedScale( -300, 200 );
152

153         LegendProperties legendProperties = null; //new LegendProperties();
154

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