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