KickJava   Java API By Example, From Geeks To Geeks.

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


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.properties.PieChart2DProperties;
40 import org.krysalis.jcharts.properties.LegendProperties;
41 import org.krysalis.jcharts.properties.ChartProperties;
42 import org.krysalis.jcharts.properties.util.ChartStroke;
43 import org.krysalis.jcharts.chartData.ChartDataException;
44 import org.krysalis.jcharts.chartData.PieChartDataSet;
45 import org.krysalis.jcharts.nonAxisChart.PieChart2D;
46 import org.krysalis.jcharts.types.PieLabelType;
47
48 import java.awt.*;
49
50
51 /*************************************************************************************
52  *
53  * @author Nathaniel Auvil
54  * @version $Id: PieChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
55  ************************************************************************************/

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

64     public void run() throws Throwable JavaDoc
65     {
66         this.basicChart();
67         this.zeroDegreeOffsetChart();
68         this.borderStroke();
69         this.borderPaint();
70
71         this.pieValueLabels();
72         this.pieLegendLabels();
73     }
74
75
76     /******************************************************************************************/
77     private void outputChart( PieChart2DProperties pieChart2DProperties, String JavaDoc name ) throws ChartDataException
78     {
79         double[] data= { 81d, 55d, 39d, 20.6d };
80         String JavaDoc[] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Corvette Z06" };
81         Paint[] paints= { Color.lightGray, Color.green, Color.blue, Color.red };
82
83         PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart2DProperties );
84
85         PieChart2D pieChart2D= new PieChart2D( pieChartDataSet, new LegendProperties(), new ChartProperties(), 400, 350 );
86         super.exportImage( pieChart2D, name );
87     }
88
89
90     /******************************************************************************************/
91     private void basicChart() throws Throwable JavaDoc
92     {
93         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
94         this.outputChart( pieChart2DProperties, "pieChartBasic" );
95     }
96
97
98     /******************************************************************************************/
99     private void zeroDegreeOffsetChart() throws Throwable JavaDoc
100     {
101         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
102         pieChart2DProperties.setZeroDegreeOffset( 45f );
103         this.outputChart( pieChart2DProperties, "pieChartZeroOffset" );
104     }
105
106
107     /******************************************************************************************/
108     private void borderStroke() throws Throwable JavaDoc
109     {
110         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
111         pieChart2DProperties.setBorderChartStroke( new ChartStroke( new BasicStroke( 4f ), Color.black ) );
112         this.outputChart( pieChart2DProperties, "pieChartBorderStroke" );
113     }
114
115
116     /******************************************************************************************/
117     private void borderPaint() throws Throwable JavaDoc
118     {
119 /*
120         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
121         pieChart2DProperties.setBorderPaint( Color.gray );
122         this.outputChart( pieChart2DProperties, "pieChartBorderPaint" );
123 */

124     }
125
126
127     private void pieValueLabels() throws ChartDataException
128     {
129         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
130         pieChart2DProperties.setPieLabelType( PieLabelType.VALUE_LABELS );
131         this.outputChart( pieChart2DProperties, "pieChartValueLabels" );
132     }
133
134     private void pieLegendLabels() throws ChartDataException
135     {
136         PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
137         pieChart2DProperties.setPieLabelType( PieLabelType.LEGEND_LABELS );
138
139         double[] data= { 81d, 55d, 39d, 20.6d };
140         String JavaDoc[] labels= { "BMW M5", "BMW M3", "Viper GTS-R", "Audi S6" };
141         Paint[] paints= { Color.lightGray, Color.green, Color.blue, Color.red };
142
143         PieChartDataSet pieChartDataSet= new PieChartDataSet( "Cars That Own", data, labels, paints, pieChart2DProperties );
144         PieChart2D pieChart2D= new PieChart2D( pieChartDataSet, null, new ChartProperties(), 400, 350 );
145         super.exportImage( pieChart2D, "pieChartLegendLabels" );
146     }
147 }
148
149
150
151
152
153
Popular Tags