001: /***********************************************************************************************
002: * File Info: $Id: AreaTestDriver.java,v 1.3 2004/05/31 16:25:42 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.properties.*;
051: import org.krysalis.jcharts.types.ChartType;
052: import org.krysalis.jcharts.axisChart.AxisChart;
053:
054: import java.awt.*;
055:
056: /******************************************************************************************
057: * This file provides examples of how to create all the different chart types provided by
058: * this package.
059: *
060: *******************************************************************************************/
061: public class AreaTestDriver extends AxisChartTestBase {
062:
063: boolean supportsImageMap() {
064: return false;
065: }
066:
067: /******************************************************************************************
068: * Separate this so can use for combo chart test
069: *
070: ******************************************************************************************/
071: static ChartTypeProperties getChartTypeProperties(
072: int numberOfDataSets) {
073: /*
074: Stroke[] strokes= new Stroke[ numberOfDataSets ];
075: for( int j=0; j < numberOfDataSets; j++ )
076: {
077: strokes[ j ]= LineChartProperties.DEFAULT_LINE_STROKE;
078: }
079: strokes[ 0 ]= new BasicStroke( 3.0f );
080:
081: Shape[] shapes= new Shape[ numberOfDataSets ];
082: for( int j=0; j < numberOfDataSets; j++ )
083: {
084: shapes[ j ]= PointChartProperties.SHAPE_DIAMOND;
085: }
086: shapes[ 0 ]= PointChartProperties.SHAPE_CIRCLE;
087: */
088:
089: return new AreaChartProperties();
090: }
091:
092: /******************************************************************************************
093: *
094: *
095: ******************************************************************************************/
096: DataSeries getDataSeries() throws ChartDataException {
097: DataSeries dataSeries;
098: AxisChartDataSet axisChartDataSet;
099:
100: int dataSize = (int) TestDataGenerator.getRandomNumber(10, 50);
101: int numberOfDataSets = (int) TestDataGenerator.getRandomNumber(
102: 1, 3);
103:
104: dataSeries = super .createDataSeries(dataSize);
105:
106: ChartType chartType = null;
107: if (TestDataGenerator.getRandomNumber(1.0d) > 0.5) {
108: chartType = ChartType.AREA;
109: } else {
110: chartType = ChartType.AREA_STACKED;
111: }
112:
113: axisChartDataSet = super .createAxisChartDataSet(chartType,
114: getChartTypeProperties(numberOfDataSets),
115: numberOfDataSets, dataSize, 0, 5000);
116:
117: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
118:
119: return dataSeries;
120: }
121:
122: public static void main(String[] args) throws ChartDataException,
123: PropertyException {
124:
125: //StackedAreaChartProperties stacked= new StackedAreaChartProperties();
126: AreaChartProperties areaChartProperties = new AreaChartProperties();
127:
128: double[][] data = { { 10, 15, 30 }, { 30, 30, 10 },
129: { 20, 25, 20 } };
130: Paint[] paints = { new Color(0, 255, 0, 100),
131: new Color(255, 0, 0, 100), new Color(0, 0, 255, 100) };
132: String[] legendLabels = { "Legend Label", "Legend Label",
133: "Legend Label" };
134: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
135: legendLabels, paints, ChartType.AREA,
136: areaChartProperties);
137:
138: String[] axisLabels = { "1", "2", "3" };
139: DataSeries dataSeries = new DataSeries(axisLabels,
140: "X-Axis Title", "Y-Axis Title", "Chart Title");
141: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
142:
143: ChartProperties chartProperties = new ChartProperties();
144: chartProperties.setEdgePadding(50);
145:
146: AxisProperties axisProperties = new AxisProperties(false);
147:
148: DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
149: .getYAxisProperties();
150: dataAxisProperties.setNumItems(4);
151: dataAxisProperties.setRoundToNearest(1);
152:
153: LegendProperties legendProperties = new LegendProperties();
154:
155: AxisChart axisChart = new AxisChart(dataSeries,
156: chartProperties, axisProperties, legendProperties, 500,
157: 400);
158:
159: ChartTestDriver.exportImage(axisChart, "AreaChartTest.png");
160:
161: }
162:
163: }
|