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.samples;
034:
035: import org.krysalis.jcharts.axisChart.AxisChart;
036: import org.krysalis.jcharts.chartData.AxisChartDataSet;
037: import org.krysalis.jcharts.chartData.ChartDataException;
038: import org.krysalis.jcharts.chartData.DataSeries;
039: import org.krysalis.jcharts.properties.AreaChartProperties;
040: import org.krysalis.jcharts.properties.AxisProperties;
041: import org.krysalis.jcharts.properties.AxisTypeProperties;
042: import org.krysalis.jcharts.properties.ChartProperties;
043: import org.krysalis.jcharts.properties.LegendProperties;
044: import org.krysalis.jcharts.properties.StackedAreaChartProperties;
045: import org.krysalis.jcharts.properties.util.ChartFont;
046: import org.krysalis.jcharts.test.TestDataGenerator;
047: import org.krysalis.jcharts.types.ChartType;
048:
049: import java.awt.*;
050:
051: /*************************************************************************************
052: *
053: * @author Nathaniel Auvil
054: * @version $Id: AreaChartSamples.java,v 1.1 2003/08/09 19:01:20 nathaniel_auvil Exp $
055: ************************************************************************************/
056: public class AreaChartSamples extends Sample {
057:
058: protected String getSubdir() {
059: return "area/";
060: }
061:
062: private AxisChart getAreaChartVerticalLabels()
063: throws ChartDataException {
064: double[][] data = TestDataGenerator.getRandomNumbers(3, 10, 0,
065: 5000);
066: Paint[] paints = TestDataGenerator.getRandomPaints(3);
067: String[] legendLabels = { "Bugs", "Security Holes", "Backdoors" };
068: AreaChartProperties areaChartProperties = new AreaChartProperties();
069: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
070: legendLabels, paints, ChartType.AREA,
071: areaChartProperties);
072:
073: String[] xAxisLabels = { "1995", "1996", "1997", "1998",
074: "1999", "2000", "2001", "2002", "2003", "2004" };
075: DataSeries dataSeries = new DataSeries(xAxisLabels, "Years",
076: "Incidence", "Micro$oft At Work");
077: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
078:
079: ChartProperties chartProperties = new ChartProperties();
080: chartProperties.setEdgePadding(20);
081: chartProperties
082: .setTitleFont(new ChartFont(new Font(
083: "Georgia Negreta cursiva", Font.PLAIN, 14),
084: Color.black));
085:
086: AxisProperties axisProperties = new AxisProperties(false);
087: axisProperties.setXAxisLabelsAreVertical(true);
088: axisProperties.getYAxisProperties().setShowGridLines(
089: AxisTypeProperties.GRID_LINES_ALL);
090:
091: ChartFont scaleFont = new ChartFont(new Font(
092: "Georgia Negreta cursiva", Font.PLAIN, 13), Color.black);
093: axisProperties.getXAxisProperties()
094: .setScaleChartFont(scaleFont);
095: axisProperties.getYAxisProperties()
096: .setScaleChartFont(scaleFont);
097:
098: ChartFont axisTitleFont = new ChartFont(new Font(
099: "Arial Narrow", Font.PLAIN, 12), Color.black);
100: axisProperties.getXAxisProperties().setAxisTitleChartFont(
101: axisTitleFont);
102: axisProperties.getYAxisProperties().setAxisTitleChartFont(
103: axisTitleFont);
104:
105: LegendProperties legendProperties = new LegendProperties();
106: AxisChart axisChart = new AxisChart(dataSeries,
107: chartProperties, axisProperties, legendProperties, 500,
108: 400);
109:
110: return axisChart;
111: }
112:
113: private AxisChart getStackedAreaChart() throws ChartDataException {
114: double[][] data = TestDataGenerator.getRandomNumbers(3, 10, 0,
115: 5000);
116: Paint[] paints = TestDataGenerator.getRandomPaints(3);
117: String[] legendLabels = { "Bugs", "Security Holes", "Backdoors" };
118: StackedAreaChartProperties stackedAreaChartProperties = new StackedAreaChartProperties();
119: AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
120: legendLabels, paints, ChartType.AREA_STACKED,
121: stackedAreaChartProperties);
122:
123: String[] xAxisLabels = { "1995", "1996", "1997", "1998",
124: "1999", "2000", "2001", "2002", "2003", "2004" };
125: DataSeries dataSeries = new DataSeries(xAxisLabels, "Years",
126: "Incidence", "Micro$oft At Work");
127: dataSeries.addIAxisPlotDataSet(axisChartDataSet);
128:
129: ChartProperties chartProperties = new ChartProperties();
130: chartProperties.setEdgePadding(20);
131: chartProperties
132: .setTitleFont(new ChartFont(new Font(
133: "Georgia Negreta cursiva", Font.PLAIN, 14),
134: Color.black));
135:
136: AxisProperties axisProperties = new AxisProperties(false);
137: axisProperties.setXAxisLabelsAreVertical(true);
138: axisProperties.getYAxisProperties().setShowGridLines(
139: AxisTypeProperties.GRID_LINES_ALL);
140:
141: ChartFont scaleFont = new ChartFont(new Font(
142: "Georgia Negreta cursiva", Font.PLAIN, 13), Color.black);
143: axisProperties.getXAxisProperties()
144: .setScaleChartFont(scaleFont);
145: axisProperties.getYAxisProperties()
146: .setScaleChartFont(scaleFont);
147:
148: ChartFont axisTitleFont = new ChartFont(new Font(
149: "Arial Narrow", Font.PLAIN, 12), Color.black);
150: axisProperties.getXAxisProperties().setAxisTitleChartFont(
151: axisTitleFont);
152: axisProperties.getYAxisProperties().setAxisTitleChartFont(
153: axisTitleFont);
154:
155: LegendProperties legendProperties = new LegendProperties();
156: AxisChart axisChart = new AxisChart(dataSeries,
157: chartProperties, axisProperties, legendProperties, 500,
158: 400);
159:
160: return axisChart;
161: }
162:
163: protected void render() throws ChartDataException {
164: super .encode(this .getAreaChartVerticalLabels(),
165: "areaChartVertical");
166: super .encode(this .getStackedAreaChart(), "stackedAreaChart");
167: }
168: }
|