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.LegendProperties;
041: import org.krysalis.jcharts.properties.AxisProperties;
042: import org.krysalis.jcharts.properties.ChartProperties;
043: import org.krysalis.jcharts.properties.LineChartProperties;
044: import org.krysalis.jcharts.properties.PointChartProperties;
045: import org.krysalis.jcharts.types.ChartType;
046: import org.krysalis.jcharts.axisChart.AxisChart;
047:
048: import java.awt.*;
049:
050: /*************************************************************************************
051: *
052: * @author Nathaniel Auvil
053: * @version $Id: ComboChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
054: ************************************************************************************/
055: public class ComboChartsGuide extends AxisChartsGuide {
056:
057: /*****************************************************************************************
058: * Tests a 'real' data set and usage.
059: *
060: * @throws ChartDataException
061: ******************************************************************************************/
062: public void run() throws ChartDataException {
063: this .stackedAreaLine();
064: }
065:
066: /*****************************************************************************************/
067: private void stackedAreaLine() throws ChartDataException {
068: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
069: "2002", "2003", "2004" };
070: String xAxisTitle = "Years";
071: String yAxisTitle = "Problems";
072: String title = "Micro$oft at Work";
073: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
074: yAxisTitle, title);
075:
076: double[][] data = TestDataGenerator.getRandomNumbers(3, 7, 0,
077: 5000);
078: String[] legendLabels = { "Bugs", "Security Holes", "Backdoors" };
079: Paint[] paints = TestDataGenerator.getRandomPaints(3);
080:
081: AreaChartProperties areaChartProperties = new AreaChartProperties();
082: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
083: legendLabels, paints, ChartType.AREA,
084: areaChartProperties);
085: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
086:
087: data = TestDataGenerator.getRandomNumbers(2, 7, 1000, 5000);
088: legendLabels = new String[] { "Patches", "New Patch Bugs" };
089: paints = new Paint[] { Color.black, Color.red };
090:
091: Stroke[] strokes = { LineChartProperties.DEFAULT_LINE_STROKE,
092: LineChartProperties.DEFAULT_LINE_STROKE };
093: Shape[] shapes = { PointChartProperties.SHAPE_CIRCLE,
094: PointChartProperties.SHAPE_TRIANGLE };
095: LineChartProperties lineChartProperties = new LineChartProperties(
096: strokes, shapes);
097: axisChartDataSet = new AxisChartDataSet(data, legendLabels,
098: paints, ChartType.LINE, lineChartProperties);
099: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
100:
101: ChartProperties chartProperties = new ChartProperties();
102: AxisProperties axisProperties = new AxisProperties();
103: LegendProperties legendProperties = new LegendProperties();
104:
105: AxisChart axisChart = new AxisChart(dataSeries,
106: chartProperties, axisProperties, legendProperties,
107: AxisChartsGuide.width, AxisChartsGuide.height);
108:
109: super .exportImage(axisChart, "stackedArea");
110:
111: }
112:
113: }
|