001: /***********************************************************************************************
002: * File Info: $Id: ClusteredBarTestDriver.java,v 1.2 2003/12/07 14:03:51 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 org.krysalis.jcharts.chartData.*;
050: import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
051: import org.krysalis.jcharts.properties.*;
052: import org.krysalis.jcharts.properties.util.ChartStroke;
053: import org.krysalis.jcharts.types.ChartType;
054: import org.krysalis.jcharts.axisChart.customRenderers.axisValue.renderers.*;
055: import org.krysalis.jcharts.axisChart.AxisChart;
056:
057: import java.awt.*;
058:
059: /******************************************************************************************
060: * This file provides examples of how to create all the different chart types provided by
061: * this package.
062: *
063: *******************************************************************************************/
064: public class ClusteredBarTestDriver extends AxisChartTestBase {
065: boolean supportsImageMap() {
066: return true;
067: }
068:
069: /******************************************************************************************
070: *
071: *
072: ******************************************************************************************/
073: DataSeries getDataSeries() throws ChartDataException {
074: ClusteredBarChartProperties clusteredBarChartProperties;
075: DataSeries dataSeries;
076: AxisChartDataSet axisChartDataSet;
077:
078: int dataSize = (int) TestDataGenerator.getRandomNumber(1, 10);
079: int numberOfDataSets = (int) TestDataGenerator.getRandomNumber(
080: 1, 4);
081:
082: dataSeries = super .createDataSeries(dataSize);
083:
084: clusteredBarChartProperties = new ClusteredBarChartProperties();
085:
086: axisChartDataSet = super .createAxisChartDataSet(
087: ChartType.BAR_CLUSTERED, clusteredBarChartProperties,
088: numberOfDataSets, dataSize, -5000, 5000);
089:
090: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
091:
092: return dataSeries;
093: }
094:
095: /*****************************************************************************************
096: *
097: * @param args
098: * @throws PropertyException
099: * @throws ChartDataException
100: *****************************************************************************************/
101: public static void main(String[] args) throws PropertyException,
102: ChartDataException {
103: ClusteredBarChartProperties clusteredBarChartProperties = new ClusteredBarChartProperties();
104:
105: //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
106: //clusteredBarChartProperties.addPreRenderEventListener( backgroundRenderer );
107:
108: ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer(
109: false, false, false, 0);
110: valueLabelRenderer
111: .setValueLabelPosition(ValueLabelPosition.ON_TOP);
112: valueLabelRenderer.useVerticalLabels(false);
113: clusteredBarChartProperties
114: .addPostRenderEventListener(valueLabelRenderer);
115:
116: double[][] data = { { 280, 0, -150, 90 }, { 80, 216, -10, 30 } };
117: Paint[] paints = { Color.yellow, Color.blue };
118: String[] legendLabels = { "Test Legend Label", "other data" };
119: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
120: legendLabels, paints, ChartType.BAR_CLUSTERED,
121: clusteredBarChartProperties);
122:
123: String[] axisLabels = { "1900", "1950", "2000", "2050" };
124: IAxisDataSeries dataSeries = new DataSeries(axisLabels,
125: "Cookies", "Years", null);
126: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
127:
128: ChartProperties chartProperties = new ChartProperties();
129: AxisProperties axisProperties = new AxisProperties(false);
130:
131: axisProperties.getYAxisProperties().setShowGridLines(
132: AxisTypeProperties.GRID_LINES_NONE);
133: axisProperties.getYAxisProperties().setAxisStroke(
134: new ChartStroke(new BasicStroke(1.5f), Color.red));
135:
136: DataAxisProperties yAxis = (DataAxisProperties) axisProperties
137: .getYAxisProperties();
138: yAxis.setRoundToNearest(1);
139: //xAxis.setUserDefinedScale( -300, 200 );
140:
141: LegendProperties legendProperties = null; //new LegendProperties();
142:
143: AxisChart axisChart = new AxisChart(dataSeries,
144: chartProperties, axisProperties, legendProperties, 500,
145: 400);
146:
147: ChartTestDriver.exportImage(axisChart,
148: "ClusteredBarChartTest.png");
149: }
150:
151: }
|