KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.krysalis.jcharts.demo.userGuide;
37
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.PointChartProperties;
44 import org.krysalis.jcharts.properties.ChartProperties;
45 import org.krysalis.jcharts.properties.AxisProperties;
46 import org.krysalis.jcharts.properties.LegendProperties;
47 import org.krysalis.jcharts.types.ChartType;
48 import org.krysalis.jcharts.axisChart.AxisChart;
49
50 import java.awt.*;
51
52
53 /*************************************************************************************
54  *
55  * @author Nathaniel Auvil
56  * @version $Id: PointChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
57  ************************************************************************************/

58 public class PointChartsGuide extends AxisChartsGuide
59 {
60
61     /*****************************************************************************************/
62     public PointChartsGuide() throws Throwable JavaDoc
63     {
64         super();
65     }
66
67
68     /*****************************************************************************************
69     * Tests a 'real' data set and usage.
70     *
71     * @throws ChartDataException
72     ******************************************************************************************/

73     public void run() throws ChartDataException
74     {
75         this.basicChart();
76         this.shapes();
77         this.nullValues();
78     }
79
80
81     /*****************************************************************************************
82     *
83     *
84     ******************************************************************************************/

85     private void basicChart() throws ChartDataException
86     {
87         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
88         String JavaDoc xAxisTitle= "Years";
89         String JavaDoc yAxisTitle= "Problems";
90         String JavaDoc title= "Micro$oft at Work";
91         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
92
93         double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 }, { 150, 15, 6, 62, -54, 10, 84 } };
94         String JavaDoc[] legendLabels= { "Bugs", "Security Holes" };
95         Paint[] paints= TestDataGenerator.getRandomPaints( 2 );
96
97         Shape[] shapes= { PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE };
98         boolean[] fillPointFlags= { true, true };
99         Paint[] outlinePaints= { Color.black, Color.black };
100         PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints );
101
102         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties );
103
104         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
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, "basicChart" );
113     }
114
115
116
117     /******************************************************************************************/
118     private void shapes() throws ChartDataException
119     {
120         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
121         String JavaDoc xAxisTitle= "Years";
122         String JavaDoc yAxisTitle= "Problems";
123         String JavaDoc title= "Micro$oft at Work";
124         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
125
126
127         double[][] data= TestDataGenerator.getRandomNumbers( 1, 7, 0, 6000 );
128         String JavaDoc[] legendLabels= { "Bugs" };
129         Paint[] paints= TestDataGenerator.getRandomPaints( 1 );
130
131         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE };
132         boolean[] fillPointFlags= { false };
133         Paint[] outlinePaints= { Color.red };
134         PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints );
135
136         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties );
137
138         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
139
140         ChartProperties chartProperties= new ChartProperties();
141         AxisProperties axisProperties= new AxisProperties();
142         LegendProperties legendProperties= new LegendProperties();
143
144         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
145
146         super.exportImage( axisChart, "shapes" );
147     }
148
149
150     /******************************************************************************************/
151     private void nullValues() throws ChartDataException
152     {
153         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
154         String JavaDoc xAxisTitle= "Years";
155         String JavaDoc yAxisTitle= "Problems";
156         String JavaDoc title= "Micro$oft at Work";
157         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
158
159
160         double[][] data= TestDataGenerator.getRandomNumbers( 1, 7, 0, 6000 );
161         data[ 0 ][ 3 ]= Double.NaN;
162         data[ 0 ][ 4 ]= Double.NaN;
163
164         String JavaDoc[] legendLabels= { "Bugs" };
165         Paint[] paints= TestDataGenerator.getRandomPaints( 1 );
166
167         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE };
168         boolean[] fillPointFlags= { true };
169         Paint[] outlinePaints= { Color.black };
170         PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints );
171
172         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties );
173
174         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
175
176         ChartProperties chartProperties= new ChartProperties();
177         AxisProperties axisProperties= new AxisProperties();
178         LegendProperties legendProperties= new LegendProperties();
179
180         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
181
182         super.exportImage( axisChart, "nullValues" );
183     }
184
185 }
186
187
Popular Tags