KickJava   Java API By Example, From Geeks To Geeks.

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


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.axisChart.AxisChart;
40 import org.krysalis.jcharts.chartData.ChartDataException;
41 import org.krysalis.jcharts.chartData.DataSeries;
42 import org.krysalis.jcharts.properties.AreaChartProperties;
43 import org.krysalis.jcharts.properties.AxisProperties;
44 import org.krysalis.jcharts.properties.ChartProperties;
45 import org.krysalis.jcharts.properties.LegendProperties;
46 import org.krysalis.jcharts.properties.util.ChartStroke;
47 import org.krysalis.jcharts.types.ChartType;
48
49 import java.awt.*;
50
51
52 /*************************************************************************************
53  *
54  * @author Nathaniel Auvil
55  * @version $Id: AllChartsGuide.java,v 1.2 2003/06/25 01:40:15 nathaniel_auvil Exp $
56  ************************************************************************************/

57 public class AllChartsGuide extends UserGuideBase
58 {
59     private DataSeries dataSeries;
60
61
62
63     public AllChartsGuide() throws ChartDataException
64     {
65         this.dataSeries= AxisChartsGuide.createDataSeries();
66         this.dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) );
67     }
68
69
70     /*****************************************************************************************
71     * Tests a 'real' data set and usage.
72     *
73     * @throws Throwable
74     ******************************************************************************************/

75     public void run() throws Throwable JavaDoc
76     {
77         this.chartTitle();
78         this.chartNoTitle();
79       this.chartTitleWrapping();
80
81         this.backgroundPaint();
82         this.chartBorder();
83         this.edgePadding();
84     }
85
86
87     /********************************************************************************************/
88     private void backgroundPaint() throws Throwable JavaDoc
89     {
90         ChartProperties chartProperties= this.getChartProperties();
91         GradientPaint paint= new GradientPaint( 250, 0, Color.white,
92                                                              250, 800, new Color( 0, 255, 255, 220 ) );
93         chartProperties.setBackgroundPaint( paint );
94
95         AxisProperties axisProperties= new AxisProperties();
96         axisProperties.setXAxisLabelsAreVertical( true );
97         LegendProperties legendProperties= new LegendProperties();
98
99         AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
100
101         super.exportImage( axisChart, "backgroundPaint" );
102     }
103
104
105     /*******************************************************************************************/
106     private void chartBorder() throws Throwable JavaDoc
107     {
108         ChartProperties chartProperties= this.getChartProperties();
109
110         ChartStroke borderStroke= new ChartStroke( new BasicStroke( 2.0f ), Color.red );
111         chartProperties.setBorderStroke( borderStroke );
112
113         AxisProperties axisProperties= new AxisProperties();
114         axisProperties.setXAxisLabelsAreVertical( true );
115         LegendProperties legendProperties= new LegendProperties();
116
117         AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
118
119         super.exportImage( axisChart, "chartBorder" );
120     }
121
122
123     /********************************************************************************************/
124     private void edgePadding() throws Throwable JavaDoc
125     {
126         ChartProperties chartProperties= this.getChartProperties();
127         chartProperties.setEdgePadding( 50f );
128       chartProperties.setBorderStroke( ChartStroke.DEFAULT_CHART_OUTLINE );
129
130         AxisProperties axisProperties= new AxisProperties();
131       axisProperties.setXAxisLabelsAreVertical( true );
132         LegendProperties legendProperties= new LegendProperties();
133
134         AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
135
136
137         super.exportImage( axisChart, "edgePadding" );
138     }
139
140
141     /********************************************************************************************/
142     private void chartTitle() throws Throwable JavaDoc
143     {
144         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
145         DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", "Micro$oft Bug Production" );
146         dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) );
147
148         ChartProperties chartProperties= this.getChartProperties();
149
150         AxisProperties axisProperties= new AxisProperties();
151         axisProperties.setXAxisLabelsAreVertical( true );
152         LegendProperties legendProperties= new LegendProperties();
153
154         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
155
156         super.exportImage( axisChart, "chartTitle" );
157     }
158
159     /********************************************************************************************/
160     private void chartNoTitle() throws Throwable JavaDoc
161     {
162         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
163         DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", null );
164         dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) );
165
166         ChartProperties chartProperties= this.getChartProperties();
167
168         AxisProperties axisProperties= new AxisProperties();
169         axisProperties.setXAxisLabelsAreVertical( true );
170         LegendProperties legendProperties= new LegendProperties();
171
172         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
173
174         super.exportImage( axisChart, "chartNoTitle" );
175     }
176
177
178     /********************************************************************************************/
179     private void chartTitleWrapping() throws Throwable JavaDoc
180     {
181         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
182         DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", "The Micro$ofties have been so very, very, very, busy adding Bugs, this title is going to wrap to the next line" );
183
184         dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) );
185
186         ChartProperties chartProperties= this.getChartProperties();
187
188         AxisProperties axisProperties= new AxisProperties();
189         axisProperties.setXAxisLabelsAreVertical( true );
190         LegendProperties legendProperties= new LegendProperties();
191
192         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
193
194         super.exportImage( axisChart, "chartTitleWrapping" );
195     }
196
197
198     /*******************************************************************************************
199      *
200      * @return
201      *****************************************************************************************/

202     private ChartProperties getChartProperties()
203     {
204         ChartProperties chartProperties= new ChartProperties();
205         //chartProperties.setBorderStroke( ChartStroke.DEFAULT_CHART_OUTLINE );
206
chartProperties.setEdgePadding( 20 );
207         return chartProperties;
208     }
209 }
210
211
212
213
214
215
Popular Tags