KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.BasicStroke JavaDoc;
40 import java.awt.Color JavaDoc;
41 import java.awt.Paint JavaDoc;
42
43 import org.krysalis.jcharts.chartData.ChartDataException;
44 import org.krysalis.jcharts.chartData.PieChartDataSet;
45 import org.krysalis.jcharts.nonAxisChart.PieChart3D;
46 import org.krysalis.jcharts.properties.ChartProperties;
47 import org.krysalis.jcharts.properties.LegendProperties;
48 import org.krysalis.jcharts.properties.PieChart3DProperties;
49 import org.krysalis.jcharts.properties.util.ChartStroke;
50 import org.krysalis.jcharts.types.PieLabelType;
51
52
53 /*************************************************************************************
54  *
55  * @author Nathaniel Auvil
56  * @version $Id: PieChart3DGuide.java,v 1.2 2003/12/13 23:35:28 nathaniel_auvil Exp $
57  ************************************************************************************/

58 public class PieChart3DGuide extends UserGuideBase
59 {
60
61     /*****************************************************************************************
62     * Tests a 'real' data set and usage.
63     *
64     * @throws Throwable
65     ******************************************************************************************/

66     public void run() throws Throwable JavaDoc
67     {
68         this.basicChart();
69         this.zeroDegreeOffsetChart();
70         this.depth();
71         this.borderStroke();
72         this.borderPaint();
73
74         this.pieValueLabels();
75         this.pieLegendLabels();
76     }
77
78
79     /******************************************************************************************/
80     private void outputChart( PieChart3DProperties pieChart3DProperties, String JavaDoc name ) throws ChartDataException
81     {
82         double[] data= { 81d, 55d, 39d, 20.6d };
83         String JavaDoc[] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Corvette Z06" };
84         Paint JavaDoc[] paints= { Color.lightGray, Color.green, Color.blue, Color.red };
85
86         PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart3DProperties );
87
88         PieChart3D pieChart3D= new PieChart3D( pieChartDataSet, new LegendProperties(), new ChartProperties(), 600, 350 );
89         super.exportImage( pieChart3D, name );
90     }
91
92
93     /******************************************************************************************/
94     private void basicChart() throws Throwable JavaDoc
95     {
96         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
97         this.outputChart( pieChart3DProperties, "pieChart3DBasic" );
98     }
99
100
101     /******************************************************************************************/
102     private void zeroDegreeOffsetChart() throws Throwable JavaDoc
103     {
104         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
105         pieChart3DProperties.setZeroDegreeOffset( 45f );
106         this.outputChart( pieChart3DProperties, "pieChart3DZeroOffset" );
107     }
108
109
110     /******************************************************************************************/
111     private void depth() throws Throwable JavaDoc
112     {
113         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
114         pieChart3DProperties.setDepth( 50 );
115         this.outputChart( pieChart3DProperties, "pieChart3DDepth" );
116     }
117
118
119     /******************************************************************************************/
120     private void borderStroke() throws Throwable JavaDoc
121     {
122         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
123         pieChart3DProperties.setBorderChartStroke( new ChartStroke( new BasicStroke JavaDoc( 4f ), Color.black ) );
124         this.outputChart( pieChart3DProperties, "pieChart3DBorderStroke" );
125     }
126
127
128     /******************************************************************************************/
129     private void borderPaint() throws Throwable JavaDoc
130     {
131 /*
132         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
133         pieChart2DProperties.setBorderPaint( Color.gray );
134         this.outputChart( pieChart2DProperties, "pieChart3DBorderPaint" );
135 */

136     }
137
138
139     private void pieValueLabels() throws ChartDataException
140     {
141         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
142         pieChart3DProperties.setPieLabelType( PieLabelType.VALUE_LABELS );
143         this.outputChart( pieChart3DProperties, "pieChart3DValueLabels" );
144     }
145
146     private void pieLegendLabels() throws ChartDataException
147     {
148         PieChart3DProperties pieChart3DProperties= new PieChart3DProperties();
149         pieChart3DProperties.setPieLabelType( PieLabelType.LEGEND_LABELS );
150
151         double[] data= { 81d, 55d, 39d, 20.6d };
152         String JavaDoc[] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Audi S6" };
153         Paint JavaDoc[] paints= { Color.lightGray, Color.green, Color.blue, Color.red };
154
155         PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart3DProperties );
156         PieChart3D pieChart3D= new PieChart3D( pieChartDataSet, null, new ChartProperties(), 400, 350 );
157         super.exportImage( pieChart3D, "pieChart3DLegendLabels" );
158     }
159 }
160
161
162
163
164
165
Popular Tags