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.AreaChartProperties;
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: AreaChartsGuide.java,v 1.1 2003/05/31 19:10:27 nathaniel_auvil Exp $
052: ************************************************************************************/
053: public class AreaChartsGuide extends AxisChartsGuide {
054:
055: /*****************************************************************************************
056: * Tests a 'real' data set and usage.
057: *
058: * @throws ChartDataException
059: ******************************************************************************************/
060: public void run() throws ChartDataException {
061: this .areaChart();
062: this .stackedArea();
063: }
064:
065: /*****************************************************************************************
066: *
067: *
068: ******************************************************************************************/
069: private void areaChart() throws ChartDataException {
070: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
071: "2002", "2003", "2004" };
072: String xAxisTitle = "Years";
073: String yAxisTitle = "Problems";
074: String title = "Micro$oft at Work";
075: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
076: yAxisTitle, title);
077:
078: double[][] data = TestDataGenerator.getRandomNumbers(1, 7, 0,
079: 6000);
080: String[] legendLabels = { "Bugs" };
081: Paint[] paints = TestDataGenerator.getRandomPaints(1);
082:
083: AreaChartProperties areaChartProperties = new AreaChartProperties();
084: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
085: legendLabels, paints, ChartType.AREA,
086: areaChartProperties);
087:
088: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
089:
090: ChartProperties chartProperties = new ChartProperties();
091: AxisProperties axisProperties = new AxisProperties();
092: LegendProperties legendProperties = new LegendProperties();
093:
094: AxisChart axisChart = new AxisChart(dataSeries,
095: chartProperties, axisProperties, legendProperties,
096: AxisChartsGuide.width, AxisChartsGuide.height);
097:
098: super .exportImage(axisChart, "areaChart");
099: }
100:
101: /*****************************************************************************************
102: *
103: *
104: ******************************************************************************************/
105: private void stackedArea() throws ChartDataException {
106: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
107: "2002", "2003", "2004" };
108: String xAxisTitle = "Years";
109: String yAxisTitle = "Problems";
110: String title = "Micro$oft at Work";
111: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
112: yAxisTitle, title);
113:
114: double[][] data = TestDataGenerator.getRandomNumbers(3, 7, 0,
115: 5000);
116: String[] legendLabels = { "Bugs", "Security Holes", "Backdoors" };
117: Paint[] paints = TestDataGenerator.getRandomPaints(3);
118:
119: AreaChartProperties areaChartProperties = new AreaChartProperties();
120: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
121: legendLabels, paints, ChartType.AREA,
122: areaChartProperties);
123:
124: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
125:
126: ChartProperties chartProperties = new ChartProperties();
127: AxisProperties axisProperties = new AxisProperties();
128: LegendProperties legendProperties = new LegendProperties();
129:
130: AxisChart axisChart = new AxisChart(dataSeries,
131: chartProperties, axisProperties, legendProperties,
132: AxisChartsGuide.width, AxisChartsGuide.height);
133:
134: super .exportImage(axisChart, "stackedArea");
135: }
136:
137: }
|