KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > demo > samples > AreaChartSamples


1
2 /***********************************************************************************************
3  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
4  *
5  * Redistribution and use of this software and associated documentation ("Software"), with or
6  * without modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain copyright statements and notices.
9  * Redistributions must also contain a copy of this document.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
12  * conditions and the following disclaimer in the documentation and/or other materials
13  * provided with the distribution.
14  *
15  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
16  * products derived from this Software without prior written permission of Nathaniel G.
17  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
18  *
19  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
20  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
21  * registered trademark of Nathaniel G. Auvil.
22  *
23  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
24  *
25  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
26  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
34  ************************************************************************************************/

35
36
37 package org.krysalis.jcharts.demo.samples;
38
39
40 import org.krysalis.jcharts.axisChart.AxisChart;
41 import org.krysalis.jcharts.chartData.AxisChartDataSet;
42 import org.krysalis.jcharts.chartData.ChartDataException;
43 import org.krysalis.jcharts.chartData.DataSeries;
44 import org.krysalis.jcharts.properties.AreaChartProperties;
45 import org.krysalis.jcharts.properties.AxisProperties;
46 import org.krysalis.jcharts.properties.AxisTypeProperties;
47 import org.krysalis.jcharts.properties.ChartProperties;
48 import org.krysalis.jcharts.properties.LegendProperties;
49 import org.krysalis.jcharts.properties.StackedAreaChartProperties;
50 import org.krysalis.jcharts.properties.util.ChartFont;
51 import org.krysalis.jcharts.test.TestDataGenerator;
52 import org.krysalis.jcharts.types.ChartType;
53
54 import java.awt.*;
55
56
57 /*************************************************************************************
58  *
59  * @author Nathaniel Auvil
60  * @version $Id: AreaChartSamples.java,v 1.1 2003/08/09 19:01:20 nathaniel_auvil Exp $
61  ************************************************************************************/

62 public class AreaChartSamples extends Sample
63 {
64
65     protected String JavaDoc getSubdir()
66     {
67         return "area/";
68     }
69
70
71     private AxisChart getAreaChartVerticalLabels() throws ChartDataException
72     {
73         double[][] data= TestDataGenerator.getRandomNumbers( 3, 10, 0, 5000 );
74         Paint[] paints= TestDataGenerator.getRandomPaints( 3 );
75         String JavaDoc[] legendLabels= { "Bugs", "Security Holes", "Backdoors" };
76         AreaChartProperties areaChartProperties= new AreaChartProperties();
77         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.AREA, areaChartProperties );
78
79         String JavaDoc[] xAxisLabels= { "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
80         DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Incidence", "Micro$oft At Work" );
81         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
82
83         ChartProperties chartProperties= new ChartProperties();
84         chartProperties.setEdgePadding( 20 );
85         chartProperties.setTitleFont( new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 14 ), Color.black ) );
86
87         AxisProperties axisProperties= new AxisProperties( false );
88         axisProperties.setXAxisLabelsAreVertical( true );
89         axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_ALL );
90
91         ChartFont scaleFont= new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.black );
92         axisProperties.getXAxisProperties().setScaleChartFont( scaleFont );
93         axisProperties.getYAxisProperties().setScaleChartFont( scaleFont );
94
95         ChartFont axisTitleFont= new ChartFont( new Font( "Arial Narrow", Font.PLAIN, 12 ), Color.black );
96         axisProperties.getXAxisProperties().setAxisTitleChartFont( axisTitleFont );
97         axisProperties.getYAxisProperties().setAxisTitleChartFont( axisTitleFont );
98
99         LegendProperties legendProperties= new LegendProperties();
100         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
101
102       return axisChart;
103     }
104
105
106     private AxisChart getStackedAreaChart() throws ChartDataException
107     {
108         double[][] data= TestDataGenerator.getRandomNumbers( 3, 10, 0, 5000 );
109         Paint[] paints= TestDataGenerator.getRandomPaints( 3 );
110         String JavaDoc[] legendLabels= { "Bugs", "Security Holes", "Backdoors" };
111         StackedAreaChartProperties stackedAreaChartProperties= new StackedAreaChartProperties();
112         AxisChartDataSet axisChartDataSet = new AxisChartDataSet( data, legendLabels, paints, ChartType.AREA_STACKED, stackedAreaChartProperties );
113
114         String JavaDoc[] xAxisLabels= { "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
115         DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Incidence", "Micro$oft At Work" );
116         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
117
118         ChartProperties chartProperties= new ChartProperties();
119         chartProperties.setEdgePadding( 20 );
120         chartProperties.setTitleFont( new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 14 ), Color.black ) );
121
122         AxisProperties axisProperties= new AxisProperties( false );
123         axisProperties.setXAxisLabelsAreVertical( true );
124         axisProperties.getYAxisProperties().setShowGridLines( AxisTypeProperties.GRID_LINES_ALL );
125
126         ChartFont scaleFont= new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.black );
127         axisProperties.getXAxisProperties().setScaleChartFont( scaleFont );
128         axisProperties.getYAxisProperties().setScaleChartFont( scaleFont );
129
130         ChartFont axisTitleFont= new ChartFont( new Font( "Arial Narrow", Font.PLAIN, 12 ), Color.black );
131         axisProperties.getXAxisProperties().setAxisTitleChartFont( axisTitleFont );
132         axisProperties.getYAxisProperties().setAxisTitleChartFont( axisTitleFont );
133
134         LegendProperties legendProperties= new LegendProperties();
135         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, 500, 400 );
136
137       return axisChart;
138     }
139
140
141     protected void render() throws ChartDataException
142     {
143       super.encode( this.getAreaChartVerticalLabels(), "areaChartVertical" );
144       super.encode( this.getStackedAreaChart(), "stackedAreaChart" );
145     }
146 }
147
Popular Tags