001: /***********************************************************************************************
002: * File Info: $Id: PointTestDriver.java,v 1.2 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.chartData.interfaces.IAxisDataSeries;
051: import org.krysalis.jcharts.properties.*;
052: import org.krysalis.jcharts.types.ChartType;
053: import org.krysalis.jcharts.axisChart.AxisChart;
054:
055: import java.awt.*;
056:
057: /******************************************************************************************
058: * This file provides examples of how to create all the different chart types provided by
059: * this package.
060: *
061: *******************************************************************************************/
062: class PointTestDriver extends AxisChartTestBase {
063: boolean supportsImageMap() {
064: return true;
065: }
066:
067: /******************************************************************************************
068: * Separate this so can use for combo chart test
069: *
070: ******************************************************************************************/
071: static ChartTypeProperties getChartTypeProperties(
072: int numberOfDataSets) {
073: //Shape rectangle= new Rectangle2D.Double( 0, 0, 8, 8 );
074: Shape[] shapes = { PointChartProperties.SHAPE_DIAMOND,
075: PointChartProperties.SHAPE_TRIANGLE };
076: boolean[] fillPointFlags = { true, true };
077: Paint[] outlinePaints = { Color.black, Color.blue };
078:
079: return new PointChartProperties(shapes, fillPointFlags,
080: outlinePaints);
081: }
082:
083: /*********************************************************************************************************
084: *
085: *
086: *********************************************************************************************************/
087: DataSeries getDataSeries() throws ChartDataException {
088: int dataSize = (int) TestDataGenerator.getRandomNumber(13, 15);
089: int numberOfDataSets = 2; //(int) TestDataGenerator.getRandomNumber( 1, 3 );
090:
091: DataSeries dataSeries = super .createDataSeries(dataSize);
092:
093: AxisChartDataSet axisChartDataSet = super
094: .createAxisChartDataSet(ChartType.POINT,
095: getChartTypeProperties(numberOfDataSets),
096: numberOfDataSets, dataSize, 0, 5000);
097:
098: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
099:
100: return dataSeries;
101: }
102:
103: /*****************************************************************************************
104: *
105: * @param args
106: * @throws PropertyException
107: * @throws ChartDataException
108: *****************************************************************************************/
109: public static void main(String[] args) throws PropertyException,
110: ChartDataException {
111: Shape[] shapes = { PointChartProperties.SHAPE_DIAMOND,
112: PointChartProperties.SHAPE_TRIANGLE };
113: boolean[] fillPointFlags = { true, true };
114: Paint[] outlinePaints = { Color.black, Color.blue };
115: PointChartProperties pointChartProperties = new PointChartProperties(
116: shapes, fillPointFlags, outlinePaints);
117:
118: //BackgroundRenderer backgroundRenderer = new BackgroundRenderer( new Color( 20, 20, 20, 50 ) );
119: //clusteredBarChartProperties.addPreRenderEventListener( backgroundRenderer );
120:
121: /*
122:
123: ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer( false, true, -1 );
124: valueLabelRenderer.setValueLabelPosition( ValueLabelPosition.ON_TOP );
125: valueLabelRenderer.useVerticalLabels( false );
126: clusteredBarChartProperties.addPostRenderEventListener( valueLabelRenderer );
127: */
128:
129: double[][] data = { { 280, 16, 150, 90, 60, 200, 150, 60 },
130: { 80, 216, 10, 30, 15, 90, 150, 87 } };
131: Paint[] paints = { Color.yellow, Color.blue };
132: String[] legendLabels = { "Test Legend Label", "second set" };
133: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
134: legendLabels, paints, ChartType.POINT,
135: pointChartProperties);
136:
137: String[] axisLabels = { "1900", "1950", "2000", "2050", "3000",
138: "3050", "4000", "4050" };
139: IAxisDataSeries dataSeries = new DataSeries(axisLabels,
140: "Cookies", "Years", null);
141: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
142:
143: ChartProperties chartProperties = new ChartProperties();
144: AxisProperties axisProperties = new AxisProperties(false);
145:
146: //axisProperties.getXAxisProperties().setShowAxisLabels( false );
147: //axisProperties.getYAxisProperties().setShowAxisLabels( false );
148: //axisProperties.getYAxisProperties().setShowTicks( AxisTypeProperties.TICKS_NONE );
149:
150: //axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_NONE );
151: //axisProperties.getYAxisProperties().setAxisStroke( new ChartStroke( new BasicStroke( 1.5f ), Color.red ) );
152:
153: /*
154:
155: DataAxisProperties xAxis = (DataAxisProperties) axisProperties.getXAxisProperties();
156: xAxis.setRoundToNearest( 1 );
157: xAxis.setUserDefinedScale( -300, 200 );
158: */
159:
160: LegendProperties legendProperties = new LegendProperties();
161:
162: AxisChart axisChart = new AxisChart(dataSeries,
163: chartProperties, axisProperties, legendProperties, 500,
164: 400);
165:
166: axisChart.renderWithImageMap();
167:
168: ChartTestDriver.exportImage(axisChart, "pointChartTest.png");
169: }
170:
171: }
|