KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > demo > userGuide > ComboChartsGuide


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.userGuide;
38
39 import org.krysalis.jcharts.chartData.ChartDataException;
40 import org.krysalis.jcharts.chartData.DataSeries;
41 import org.krysalis.jcharts.chartData.AxisChartDataSet;
42 import org.krysalis.jcharts.test.TestDataGenerator;
43 import org.krysalis.jcharts.properties.AreaChartProperties;
44 import org.krysalis.jcharts.properties.LegendProperties;
45 import org.krysalis.jcharts.properties.AxisProperties;
46 import org.krysalis.jcharts.properties.ChartProperties;
47 import org.krysalis.jcharts.properties.LineChartProperties;
48 import org.krysalis.jcharts.properties.PointChartProperties;
49 import org.krysalis.jcharts.types.ChartType;
50 import org.krysalis.jcharts.axisChart.AxisChart;
51
52 import java.awt.*;
53
54
55
56 /*************************************************************************************
57  *
58  * @author Nathaniel Auvil
59  * @version $Id: ComboChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
60  ************************************************************************************/

61 public class ComboChartsGuide extends AxisChartsGuide
62 {
63
64
65     /*****************************************************************************************
66     * Tests a 'real' data set and usage.
67     *
68     * @throws ChartDataException
69     ******************************************************************************************/

70     public void run() throws ChartDataException
71     {
72         this.stackedAreaLine();
73     }
74
75
76     /*****************************************************************************************/
77     private void stackedAreaLine() throws ChartDataException
78     {
79         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
80         String JavaDoc xAxisTitle= "Years";
81         String JavaDoc yAxisTitle= "Problems";
82         String JavaDoc title= "Micro$oft at Work";
83         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
84
85
86         double[][] data= TestDataGenerator.getRandomNumbers( 3, 7, 0, 5000 );
87         String JavaDoc[] legendLabels= { "Bugs", "Security Holes", "Backdoors" };
88         Paint[] paints= TestDataGenerator.getRandomPaints( 3 );
89
90         AreaChartProperties areaChartProperties= new AreaChartProperties();
91         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.AREA, areaChartProperties );
92         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
93
94
95         data= TestDataGenerator.getRandomNumbers( 2, 7, 1000, 5000 );
96         legendLabels= new String JavaDoc[]{ "Patches", "New Patch Bugs" };
97         paints= new Paint[]{ Color.black, Color.red };
98
99         Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE };
100         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE, PointChartProperties.SHAPE_TRIANGLE };
101         LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes );
102         axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties );
103         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
104
105
106         ChartProperties chartProperties= new ChartProperties();
107         AxisProperties axisProperties= new AxisProperties();
108         LegendProperties legendProperties= new LegendProperties();
109
110         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
111
112         super.exportImage( axisChart, "stackedArea" );
113
114     }
115
116
117
118 }
119
120
Popular Tags