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.demo.userGuide;
034:
035: import org.krysalis.jcharts.chartData.ChartDataException;
036: import org.krysalis.jcharts.chartData.DataSeries;
037: import org.krysalis.jcharts.chartData.AxisChartDataSet;
038: import org.krysalis.jcharts.test.TestDataGenerator;
039: import org.krysalis.jcharts.properties.LineChartProperties;
040: import org.krysalis.jcharts.properties.PointChartProperties;
041: import org.krysalis.jcharts.properties.LegendProperties;
042: import org.krysalis.jcharts.properties.AxisProperties;
043: import org.krysalis.jcharts.properties.ChartProperties;
044: import org.krysalis.jcharts.types.ChartType;
045: import org.krysalis.jcharts.axisChart.AxisChart;
046:
047: import java.awt.*;
048:
049: /*************************************************************************************
050: *
051: * @author Nathaniel Auvil
052: * @version $Id: LineChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
053: ************************************************************************************/
054: public class LineChartsGuide extends AxisChartsGuide {
055:
056: /*****************************************************************************************
057: * Tests a 'real' data set and usage.
058: *
059: * @throws ChartDataException
060: ******************************************************************************************/
061: public void run() throws ChartDataException {
062: this .basicChart();
063: this .strokes();
064: this .missingValues();
065: }
066:
067: /******************************************************************************************/
068: private void basicChart() throws ChartDataException {
069: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
070: "2002", "2003", "2004" };
071: String xAxisTitle = "Years";
072: String yAxisTitle = "Problems";
073: String title = "Micro$oft at Work";
074: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
075: yAxisTitle, title);
076:
077: double[][] data = new double[][] { { 250, 45, -36, 66, 145, 80,
078: 55 } };
079: String[] legendLabels = { "Bugs" };
080: Paint[] paints = TestDataGenerator.getRandomPaints(1);
081:
082: Stroke[] strokes = { LineChartProperties.DEFAULT_LINE_STROKE };
083: Shape[] shapes = { PointChartProperties.SHAPE_CIRCLE };
084: LineChartProperties lineChartProperties = new LineChartProperties(
085: strokes, shapes);
086:
087: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
088: legendLabels, paints, ChartType.LINE,
089: lineChartProperties);
090: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
091:
092: ChartProperties chartProperties = new ChartProperties();
093: AxisProperties axisProperties = new AxisProperties();
094: LegendProperties legendProperties = new LegendProperties();
095:
096: AxisChart axisChart = new AxisChart(dataSeries,
097: chartProperties, axisProperties, legendProperties,
098: AxisChartsGuide.width, AxisChartsGuide.height);
099:
100: super .exportImage(axisChart, "basicChart");
101: }
102:
103: /******************************************************************************************/
104: private void strokes() throws ChartDataException {
105: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
106: "2002", "2003", "2004" };
107: String xAxisTitle = "Years";
108: String yAxisTitle = "Problems";
109: String title = "Micro$oft at Work";
110: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
111: yAxisTitle, title);
112:
113: double[][] data = new double[][] {
114: { 250, 45, -36, 66, 145, 80, 55 },
115: { 150, 15, 6, 62, -54, 10, 84 } };
116: String[] legendLabels = { "Bugs", "Security Holes" };
117: Paint[] paints = TestDataGenerator.getRandomPaints(2);
118:
119: Stroke[] strokes = new Stroke[2];
120: strokes[0] = new BasicStroke(3.5f, BasicStroke.CAP_ROUND,
121: BasicStroke.JOIN_ROUND, 5f, new float[] { 5f, 5f, 10f,
122: 5f }, 4f);
123: strokes[1] = new BasicStroke(5.0f);
124: Shape[] shapes = { PointChartProperties.SHAPE_CIRCLE, null };
125: LineChartProperties lineChartProperties = new LineChartProperties(
126: strokes, shapes);
127:
128: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
129: legendLabels, paints, ChartType.LINE,
130: lineChartProperties);
131: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
132:
133: ChartProperties chartProperties = new ChartProperties();
134: AxisProperties axisProperties = new AxisProperties();
135: LegendProperties legendProperties = new LegendProperties();
136:
137: AxisChart axisChart = new AxisChart(dataSeries,
138: chartProperties, axisProperties, legendProperties,
139: AxisChartsGuide.width, AxisChartsGuide.height);
140:
141: super .exportImage(axisChart, "strokes");
142: }
143:
144: /******************************************************************************************/
145: private void missingValues() throws ChartDataException {
146: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
147: "2002", "2003", "2004" };
148: String xAxisTitle = "Years";
149: String yAxisTitle = "Problems";
150: String title = "Micro$oft at Work";
151: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
152: yAxisTitle, title);
153:
154: double[][] data = new double[][] { { 250, 45, -36, 66, 145, 80,
155: 55 } };
156: data[0][3] = Double.NaN;
157: data[0][4] = Double.NaN;
158:
159: String[] legendLabels = { "Bugs" };
160: Paint[] paints = TestDataGenerator.getRandomPaints(1);
161:
162: Stroke[] strokes = { LineChartProperties.DEFAULT_LINE_STROKE };
163: Shape[] shapes = { PointChartProperties.SHAPE_CIRCLE };
164: LineChartProperties lineChartProperties = new LineChartProperties(
165: strokes, shapes);
166:
167: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
168: legendLabels, paints, ChartType.LINE,
169: lineChartProperties);
170:
171: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
172:
173: ChartProperties chartProperties = new ChartProperties();
174: AxisProperties axisProperties = new AxisProperties();
175: LegendProperties legendProperties = new LegendProperties();
176:
177: AxisChart axisChart = new AxisChart(dataSeries,
178: chartProperties, axisProperties, legendProperties,
179: AxisChartsGuide.width, AxisChartsGuide.height);
180:
181: super .exportImage(axisChart, "missingValues");
182: }
183: }
|