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