KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 package org.krysalis.jcharts.demo.userGuide;
36
37 import org.krysalis.jcharts.chartData.ChartDataException;
38 import org.krysalis.jcharts.chartData.DataSeries;
39 import org.krysalis.jcharts.chartData.AxisChartDataSet;
40 import org.krysalis.jcharts.test.TestDataGenerator;
41 import org.krysalis.jcharts.properties.LineChartProperties;
42 import org.krysalis.jcharts.properties.PointChartProperties;
43 import org.krysalis.jcharts.properties.LegendProperties;
44 import org.krysalis.jcharts.properties.AxisProperties;
45 import org.krysalis.jcharts.properties.ChartProperties;
46 import org.krysalis.jcharts.types.ChartType;
47 import org.krysalis.jcharts.axisChart.AxisChart;
48
49 import java.awt.*;
50
51
52
53 /*************************************************************************************
54  *
55  * @author Nathaniel Auvil
56  * @version $Id: LineChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
57  ************************************************************************************/

58 public class LineChartsGuide extends AxisChartsGuide
59 {
60
61
62     /*****************************************************************************************
63     * Tests a 'real' data set and usage.
64     *
65     * @throws ChartDataException
66     ******************************************************************************************/

67     public void run() throws ChartDataException
68     {
69         this.basicChart();
70         this.strokes();
71         this.missingValues();
72     }
73
74
75
76     /******************************************************************************************/
77     private void basicChart() 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         double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } };
86         String JavaDoc[] legendLabels= { "Bugs" };
87         Paint[] paints= TestDataGenerator.getRandomPaints( 1 );
88
89         Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE };
90         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE };
91         LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes );
92
93         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties );
94         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
95
96         ChartProperties chartProperties= new ChartProperties();
97         AxisProperties axisProperties= new AxisProperties();
98         LegendProperties legendProperties= new LegendProperties();
99
100         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
101
102         super.exportImage( axisChart, "basicChart" );
103     }
104
105
106     /******************************************************************************************/
107     private void strokes() throws ChartDataException
108     {
109         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
110         String JavaDoc xAxisTitle= "Years";
111         String JavaDoc yAxisTitle= "Problems";
112         String JavaDoc title= "Micro$oft at Work";
113         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
114
115         double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 }, { 150, 15, 6, 62, -54, 10, 84 } };
116         String JavaDoc[] legendLabels= { "Bugs", "Security Holes" };
117         Paint[] paints= TestDataGenerator.getRandomPaints( 2 );
118
119         Stroke[] strokes= new Stroke[ 2 ];
120         strokes[ 0 ]= new BasicStroke( 3.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f, new float[]{ 5f, 5f, 10f, 5f}, 4f );
121         strokes[ 1 ]= new BasicStroke( 5.0f );
122         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE, null };
123         LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes );
124
125         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties );
126         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
127
128         ChartProperties chartProperties= new ChartProperties();
129         AxisProperties axisProperties= new AxisProperties();
130         LegendProperties legendProperties= new LegendProperties();
131
132         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
133
134         super.exportImage( axisChart, "strokes" );
135     }
136
137
138
139     /******************************************************************************************/
140     private void missingValues() throws ChartDataException
141     {
142         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
143         String JavaDoc xAxisTitle= "Years";
144         String JavaDoc yAxisTitle= "Problems";
145         String JavaDoc title= "Micro$oft at Work";
146         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
147
148         double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } };
149         data[ 0 ][ 3 ]= Double.NaN;
150         data[ 0 ][ 4 ]= Double.NaN;
151
152         String JavaDoc[] legendLabels= { "Bugs" };
153         Paint[] paints= TestDataGenerator.getRandomPaints( 1 );
154
155         Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE };
156         Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE };
157         LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes );
158
159         AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties );
160
161         dataSeries.addIAxisPlotDataSet( axisChartDataSet );
162
163         ChartProperties chartProperties= new ChartProperties();
164         AxisProperties axisProperties= new AxisProperties();
165         LegendProperties legendProperties= new LegendProperties();
166
167         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
168
169         super.exportImage( axisChart, "missingValues" );
170     }
171 }
172
173
Popular Tags