KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.BasicStroke JavaDoc;
38 import java.awt.Color JavaDoc;
39 import java.awt.Font JavaDoc;
40 import java.awt.Shape JavaDoc;
41 import java.awt.Stroke JavaDoc;
42
43 import org.krysalis.jcharts.axisChart.AxisChart;
44 import org.krysalis.jcharts.chartData.DataSeries;
45 import org.krysalis.jcharts.properties.AxisProperties;
46 import org.krysalis.jcharts.properties.ChartProperties;
47 import org.krysalis.jcharts.properties.ClusteredBarChartProperties;
48 import org.krysalis.jcharts.properties.LegendAreaProperties;
49 import org.krysalis.jcharts.properties.LegendProperties;
50 import org.krysalis.jcharts.properties.LineChartProperties;
51 import org.krysalis.jcharts.properties.PointChartProperties;
52 import org.krysalis.jcharts.properties.util.ChartFont;
53 import org.krysalis.jcharts.properties.util.ChartStroke;
54 import org.krysalis.jcharts.types.ChartType;
55
56
57 /*************************************************************************************
58  *
59  * @author Nathaniel Auvil
60  * @version $Id: LegendsGuide.java,v 1.6 2003/08/08 08:51:27 nicolaken Exp $
61  ************************************************************************************/

62 public class LegendsGuide extends UserGuideBase
63 {
64
65     /*****************************************************************************************
66     * Tests a 'real' data set and usage.
67     *
68     * @throws Throwable
69     ******************************************************************************************/

70     public void run() throws Throwable JavaDoc
71     {
72         this.basicLegend();
73         this.noLegend();
74         this.rightSide();
75         this.layout();
76
77         this.fonts();
78         this.backgroundPaint();
79         this.iconBorderPaint();
80         this.borderColor();
81         this.chartPadding();
82     }
83
84
85     /*****************************************************************************************
86     *
87     *
88     ******************************************************************************************/

89     private AxisChart getChart( LegendProperties legendProperties ) throws Throwable JavaDoc
90     {
91         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
92         String JavaDoc xAxisTitle= "Years";
93         String JavaDoc yAxisTitle= "Problems";
94         String JavaDoc title= "Micro$oft at Work";
95         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
96
97         Stroke JavaDoc[] strokes = new Stroke JavaDoc[]{ LineChartProperties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE };
98         Shape JavaDoc[] shapes = new Shape JavaDoc[]{ PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE, PointChartProperties.SHAPE_CIRCLE };
99         LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes );
100
101         String JavaDoc[] legendLabels= new String JavaDoc[]{ "Bugs", "Security Holes", "Backdoors" };
102         dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.LINE, lineChartProperties, 3, legendLabels, 200, 5000 ) );
103
104         ChartProperties chartProperties= new ChartProperties();
105         AxisProperties axisProperties= new AxisProperties();
106
107         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
108
109         return axisChart;
110     }
111
112
113     /*************************************************************************************************/
114     private void basicLegend() throws Throwable JavaDoc
115     {
116         LegendProperties legendProperties= new LegendProperties();
117
118         super.exportImage( this.getChart( legendProperties ), "legendBasic" );
119     }
120
121
122     /*************************************************************************************************/
123     private void noLegend() throws Throwable JavaDoc
124     {
125         LegendProperties legendProperties= null;
126
127         super.exportImage( this.getChart( legendProperties ), "noLegend" );
128     }
129
130
131     /*************************************************************************************************/
132     private void rightSide() throws Throwable JavaDoc
133     {
134         LegendProperties legendProperties= new LegendProperties();
135         legendProperties.setPlacement( LegendAreaProperties.RIGHT );
136
137         super.exportImage( this.getChart( legendProperties ), "legendOnRight" );
138     }
139
140
141     /*************************************************************************************************/
142     private void layout() throws Throwable JavaDoc
143     {
144         LegendProperties legendProperties= new LegendProperties();
145         legendProperties.setPlacement( LegendAreaProperties.LEFT );
146         legendProperties.setNumColumns( 1 );
147
148         super.exportImage( this.getChart( legendProperties ), "oneColumn" );
149     }
150
151
152
153     /*************************************************************************************************/
154     private void fonts() throws Throwable JavaDoc
155     {
156         LegendProperties legendProperties= new LegendProperties();
157         legendProperties.setChartFont( new ChartFont( new Font JavaDoc( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.red ) );
158
159         super.exportImage( this.getChart( legendProperties ), "legendFonts" );
160     }
161
162
163     /*************************************************************************************************/
164     private void backgroundPaint() throws Throwable JavaDoc
165     {
166         LegendProperties legendProperties= new LegendProperties();
167         legendProperties.setBackgroundPaint( Color.lightGray );
168
169         super.exportImage( this.getChart( legendProperties ), "legendBackgroundPaint" );
170     }
171
172
173
174     /*************************************************************************************************/
175     private void iconBorderPaint() throws Throwable JavaDoc
176     {
177         String JavaDoc[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" };
178         String JavaDoc xAxisTitle= "Years";
179         String JavaDoc yAxisTitle= "Problems";
180         String JavaDoc title= "Micro$oft at Work";
181         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
182
183         ClusteredBarChartProperties clusteredBarChartProperties= new ClusteredBarChartProperties();
184
185         String JavaDoc[] legendLabels= new String JavaDoc[]{ "Bugs", "Security Holes", "Backdoors" };
186         dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.BAR_CLUSTERED, clusteredBarChartProperties, 3, legendLabels, 200, 5000 ) );
187
188         ChartProperties chartProperties= new ChartProperties();
189         AxisProperties axisProperties= new AxisProperties();
190
191         LegendProperties legendProperties= new LegendProperties();
192         legendProperties.setIconBorderPaint( Color.red );
193
194         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
195
196         super.exportImage( axisChart, "iconBorderPaint" );
197     }
198
199
200     /*************************************************************************************************/
201     private void borderColor() throws Throwable JavaDoc
202     {
203         LegendProperties legendProperties= new LegendProperties();
204
205         ChartStroke borderStroke= new ChartStroke( new BasicStroke JavaDoc( 2.0f ), Color.blue );
206         legendProperties.setBorderStroke( borderStroke );
207
208         super.exportImage( this.getChart( legendProperties ), "borderColor" );
209     }
210
211
212     /*************************************************************************************************/
213     private void chartPadding() throws Throwable JavaDoc
214     {
215         LegendProperties legendProperties= new LegendProperties();
216         legendProperties.setChartPadding( 30 );
217
218         super.exportImage( this.getChart( legendProperties ), "chartPadding" );
219     }
220
221 }
222
223
224
225
226
227
Popular Tags