001: /***********************************************************************************************
002: * File Info: $Id: BarTestDriver.java,v 1.5 2004/05/27 02:06:39 nathaniel_auvil Exp $
003: * Copyright (C) 2000
004: * Author: Nathaniel G. Auvil
005: * Contributor(s):
006: *
007: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
008: *
009: * Redistribution and use of this software and associated documentation
010: * ("Software"), with or without modification, are permitted provided
011: * that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain copyright
014: * statements and notices. Redistributions must also contain a
015: * copy of this document.
016: *
017: * 2. Redistributions in binary form must reproduce the
018: * above copyright notice, this list of conditions and the
019: * following disclaimer in the documentation and/or other
020: * materials provided with the distribution.
021: *
022: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to
023: * endorse or promote products derived from this Software without
024: * prior written permission of Nathaniel G. Auvil. For written
025: * permission, please contact nathaniel_auvil@users.sourceforge.net
026: *
027: * 4. Products derived from this Software may not be called "jCharts"
028: * nor may "jCharts" appear in their names without prior written
029: * permission of Nathaniel G. Auvil. jCharts is a registered
030: * trademark of Nathaniel G. Auvil.
031: *
032: * 5. Due credit should be given to the jCharts Project
033: * (http://jcharts.sourceforge.net/).
034: *
035: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS
036: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
037: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
038: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
039: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
040: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
041: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
042: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
043: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
044: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
045: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
046: * OF THE POSSIBILITY OF SUCH DAMAGE.
047: ************************************************************************************************/package org.krysalis.jcharts.test;
048:
049: import java.awt.BasicStroke;
050: import java.awt.Color;
051: import java.awt.Paint;
052:
053: import org.krysalis.jcharts.axisChart.AxisChart;
054: import org.krysalis.jcharts.chartData.AxisChartDataSet;
055: import org.krysalis.jcharts.chartData.ChartDataException;
056: import org.krysalis.jcharts.chartData.DataSeries;
057: import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
058: import org.krysalis.jcharts.properties.AxisProperties;
059: import org.krysalis.jcharts.properties.AxisTypeProperties;
060: import org.krysalis.jcharts.properties.BarChartProperties;
061: import org.krysalis.jcharts.properties.ChartProperties;
062: import org.krysalis.jcharts.properties.ChartTypeProperties;
063: import org.krysalis.jcharts.properties.DataAxisProperties;
064: import org.krysalis.jcharts.properties.LegendProperties;
065: import org.krysalis.jcharts.properties.PropertyException;
066: import org.krysalis.jcharts.properties.util.ChartStroke;
067: import org.krysalis.jcharts.types.ChartType;
068:
069: /******************************************************************************************
070: * This file provides examples of how to create all the different chart types provided by
071: * this package.
072: *
073: *******************************************************************************************/
074: public final class BarTestDriver extends AxisChartTestBase {
075: boolean supportsImageMap() {
076: return true;
077: }
078:
079: /******************************************************************************************
080: * Separate this so can use for combo chart test
081: *
082: ******************************************************************************************/
083: static ChartTypeProperties getChartTypeProperties(
084: int numberOfDataSets) {
085: BarChartProperties barChartProperties = new BarChartProperties();
086: barChartProperties.setWidthPercentage(1f);
087:
088: return barChartProperties;
089: }
090:
091: /******************************************************************************************
092: *
093: *
094: ******************************************************************************************/
095: DataSeries getDataSeries() throws ChartDataException {
096: int dataSize = (int) TestDataGenerator.getRandomNumber(2, 25);
097: int numberOfDataSets = 1; //(int) TestDataGenerator.getRandomNumber( 1, 3 );
098:
099: AxisChartDataSet axisChartDataSet;
100:
101: DataSeries dataSeries = super .createDataSeries(dataSize);
102:
103: axisChartDataSet = super .createAxisChartDataSet(ChartType.BAR,
104: getChartTypeProperties(numberOfDataSets),
105: numberOfDataSets, dataSize, -200, 400);
106:
107: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
108:
109: return dataSeries;
110: }
111:
112: /*****************************************************************************************
113: *
114: * @param args
115: * @throws PropertyException
116: * @throws ChartDataException
117: *****************************************************************************************/
118: public static void main(String[] args) throws PropertyException,
119: ChartDataException {
120: BarChartProperties barChartProperties = new BarChartProperties();
121:
122: //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
123: //barChartProperties.addPreRenderEventListener( backgroundRenderer );
124:
125: /*
126: ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, true, -1 );
127: valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
128: valueLabelRenderer.useVerticalLabels( false );
129: barChartProperties.addPostRenderEventListener( valueLabelRenderer );
130: */
131:
132: double[][] data = { { .40, .60, .04, .3 } };
133: Paint[] paints = { Color.green };
134: String[] legendLabels = { "Test Legend Label" };
135: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
136: legendLabels, paints, ChartType.BAR, barChartProperties);
137:
138: String[] axisLabels = { "1900", "2000", "2010", "2050" };
139: //String[] axisLabels = {"1900", "1910", "1920", "1930", "1940", "1950", "1960", "1970", "1980", "1990", "2000" };
140: IAxisDataSeries dataSeries = new DataSeries(axisLabels,
141: "Wonka Bars", "Years", "Oompa Loompa Productivity");
142: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
143:
144: ChartProperties chartProperties = new ChartProperties();
145: AxisProperties axisProperties = new AxisProperties(false);
146:
147: axisProperties.getYAxisProperties().setShowGridLines(
148: AxisTypeProperties.GRID_LINES_ALL);
149: axisProperties.getYAxisProperties().setAxisStroke(
150: new ChartStroke(new BasicStroke(1.5f), Color.red));
151: axisProperties.getYAxisProperties().setGridLineChartStroke(
152: new ChartStroke(new BasicStroke(1.5f), Color.red));
153:
154: //axisProperties.setXAxisLabelsAreVertical( true );
155:
156: DataAxisProperties yAxis = (DataAxisProperties) axisProperties
157: .getYAxisProperties();
158: // yAxis.setUsePercentSigns( true );
159: // yAxis.setUserDefinedScale( 0, 0.05 );
160: yAxis.setNumItems(10);
161: yAxis.setRoundToNearest(-3);
162:
163: LegendProperties legendProperties = new LegendProperties();
164:
165: AxisChart axisChart = new AxisChart(dataSeries,
166: chartProperties, axisProperties, legendProperties, 500,
167: 400);
168:
169: ChartTestDriver.exportImage(axisChart, "BarChartTest.png");
170:
171: }
172:
173: }
|