001: /***********************************************************************************************
002: * File Info: $Id: LineTestDriver.java,v 1.1 2003/05/17 17:01:11 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.axisChart.AxisChart;
050: import org.krysalis.jcharts.chartData.*;
051: import org.krysalis.jcharts.properties.*;
052: import org.krysalis.jcharts.types.ChartType;
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: class LineTestDriver extends AxisChartTestBase {
062: boolean supportsImageMap() {
063: return true;
064: }
065:
066: /******************************************************************************************
067: * Separate this so can use for combo chart test
068: *
069: * @param numberOfDataSets
070: ******************************************************************************************/
071: static ChartTypeProperties getChartTypeProperties(
072: int numberOfDataSets) {
073: Stroke[] strokes = new Stroke[numberOfDataSets];
074: for (int j = 0; j < numberOfDataSets; j++) {
075: strokes[j] = LineChartProperties.DEFAULT_LINE_STROKE;
076: }
077: strokes[0] = new BasicStroke(3.0f);
078:
079: Shape[] shapes = new Shape[numberOfDataSets];
080: for (int j = 0; j < numberOfDataSets; j++) {
081: shapes[j] = PointChartProperties.SHAPE_DIAMOND;
082: }
083: shapes[0] = PointChartProperties.SHAPE_CIRCLE;
084:
085: return new LineChartProperties(strokes, shapes);
086: }
087:
088: /******************************************************************************************
089: *
090: *
091: ******************************************************************************************/
092: DataSeries getDataSeries() throws ChartDataException {
093: DataSeries dataSeries;
094: AxisChartDataSet axisChartDataSet;
095:
096: int dataSize = (int) TestDataGenerator.getRandomNumber(3, 3);
097: int numberOfDataSets = (int) TestDataGenerator.getRandomNumber(
098: 1, 1);
099:
100: dataSeries = super .createDataSeries(dataSize);
101:
102: axisChartDataSet = super .createAxisChartDataSet(ChartType.LINE,
103: getChartTypeProperties(numberOfDataSets),
104: numberOfDataSets, dataSize, 10, 5000);
105:
106: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
107:
108: return dataSeries;
109: }
110:
111: /******************************************************************************************
112: *
113: *
114: ******************************************************************************************
115: DataSeries getDataSeries() throws ChartDataException
116: {
117: String[] xAxisLabels={"1", "2", "3", "4", "5"};
118: DataSeries dataSeries=new DataSeries( xAxisLabels, "numbers", "numbers", "Bug #559177" );
119: AxisChartDataSet axisChartDataSet;
120:
121: double[][] data={{1, 2, 3, 4, 5},
122: {7, 8, Double.NaN, Double.NaN, Double.NaN},
123: {Double.NaN, Double.NaN, Double.NaN, Double.NaN, 2}};
124:
125: String[] legendLabels={"set 1", "set 2", "set 3"};
126: Paint[] paints={Color.blue, Color.red, Color.green};
127:
128: axisChartDataSet=new AxisChartDataSet( data,
129: legendLabels,
130: paints,
131: ChartType.LINE,
132: this.getChartTypeProperties( 3 ) );
133:
134: dataSeries.addIAxisPlotDataSet( axisChartDataSet );
135:
136: return dataSeries;
137:
138: }
139: */
140:
141: public static void main(String[] args) throws ChartDataException,
142: PropertyException {
143: LineChartProperties lineChartProperties = (LineChartProperties) getChartTypeProperties(1);
144: double[][] data = { { 280, 16, 150, 90 } };
145: Paint[] paints = { Color.blue };
146: String[] legendLabels = { "Test Legend Label" };
147: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
148: legendLabels, paints, ChartType.LINE,
149: lineChartProperties);
150:
151: String[] axisLabels = null; //{ "1900", "1950", "2000", "2050" };
152: DataSeries dataSeries = new DataSeries(axisLabels,
153: "X-Axis Title", "Y-Axis Title", "Chart Title");
154: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
155:
156: ChartProperties chartProperties = new ChartProperties();
157: AxisProperties axisProperties = new AxisProperties(false);
158: axisProperties.getYAxisProperties().setShowAxisLabels(false);
159: axisProperties.getXAxisProperties().setShowAxisLabels(false);
160:
161: DataAxisProperties yAxis = (DataAxisProperties) axisProperties
162: .getYAxisProperties();
163: yAxis.setUserDefinedScale(-10, 50);
164: yAxis.setNumItems(4);
165: yAxis.setRoundToNearest(1);
166:
167: LegendProperties legendProperties = new LegendProperties();
168:
169: AxisChart axisChart = new AxisChart(dataSeries,
170: chartProperties, axisProperties, legendProperties, 500,
171: 400);
172:
173: ChartTestDriver.exportImage(axisChart, "LineChartTest.png");
174:
175: }
176:
177: }
|