001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.demo.userGuide;
034:
035: import java.awt.BasicStroke;
036: import java.awt.Color;
037: import java.awt.Paint;
038:
039: import org.krysalis.jcharts.chartData.ChartDataException;
040: import org.krysalis.jcharts.chartData.PieChartDataSet;
041: import org.krysalis.jcharts.nonAxisChart.PieChart3D;
042: import org.krysalis.jcharts.properties.ChartProperties;
043: import org.krysalis.jcharts.properties.LegendProperties;
044: import org.krysalis.jcharts.properties.PieChart3DProperties;
045: import org.krysalis.jcharts.properties.util.ChartStroke;
046: import org.krysalis.jcharts.types.PieLabelType;
047:
048: /*************************************************************************************
049: *
050: * @author Nathaniel Auvil
051: * @version $Id: PieChart3DGuide.java,v 1.2 2003/12/13 23:35:28 nathaniel_auvil Exp $
052: ************************************************************************************/
053: public class PieChart3DGuide extends UserGuideBase {
054:
055: /*****************************************************************************************
056: * Tests a 'real' data set and usage.
057: *
058: * @throws Throwable
059: ******************************************************************************************/
060: public void run() throws Throwable {
061: this .basicChart();
062: this .zeroDegreeOffsetChart();
063: this .depth();
064: this .borderStroke();
065: this .borderPaint();
066:
067: this .pieValueLabels();
068: this .pieLegendLabels();
069: }
070:
071: /******************************************************************************************/
072: private void outputChart(PieChart3DProperties pieChart3DProperties,
073: String name) throws ChartDataException {
074: double[] data = { 81d, 55d, 39d, 20.6d };
075: String[] labels = { "BMW M5", "BMW M3", "Viper GTS-R",
076: "Corvette Z06" };
077: Paint[] paints = { Color.lightGray, Color.green, Color.blue,
078: Color.red };
079:
080: PieChartDataSet pieChartDataSet = new PieChartDataSet(
081: "Cars That Own", data, labels, paints,
082: pieChart3DProperties);
083:
084: PieChart3D pieChart3D = new PieChart3D(pieChartDataSet,
085: new LegendProperties(), new ChartProperties(), 600, 350);
086: super .exportImage(pieChart3D, name);
087: }
088:
089: /******************************************************************************************/
090: private void basicChart() throws Throwable {
091: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
092: this .outputChart(pieChart3DProperties, "pieChart3DBasic");
093: }
094:
095: /******************************************************************************************/
096: private void zeroDegreeOffsetChart() throws Throwable {
097: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
098: pieChart3DProperties.setZeroDegreeOffset(45f);
099: this .outputChart(pieChart3DProperties, "pieChart3DZeroOffset");
100: }
101:
102: /******************************************************************************************/
103: private void depth() throws Throwable {
104: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
105: pieChart3DProperties.setDepth(50);
106: this .outputChart(pieChart3DProperties, "pieChart3DDepth");
107: }
108:
109: /******************************************************************************************/
110: private void borderStroke() throws Throwable {
111: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
112: pieChart3DProperties.setBorderChartStroke(new ChartStroke(
113: new BasicStroke(4f), Color.black));
114: this
115: .outputChart(pieChart3DProperties,
116: "pieChart3DBorderStroke");
117: }
118:
119: /******************************************************************************************/
120: private void borderPaint() throws Throwable {
121: /*
122: PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
123: pieChart2DProperties.setBorderPaint( Color.gray );
124: this.outputChart( pieChart2DProperties, "pieChart3DBorderPaint" );
125: */
126: }
127:
128: private void pieValueLabels() throws ChartDataException {
129: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
130: pieChart3DProperties.setPieLabelType(PieLabelType.VALUE_LABELS);
131: this .outputChart(pieChart3DProperties, "pieChart3DValueLabels");
132: }
133:
134: private void pieLegendLabels() throws ChartDataException {
135: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
136: pieChart3DProperties
137: .setPieLabelType(PieLabelType.LEGEND_LABELS);
138:
139: double[] data = { 81d, 55d, 39d, 20.6d };
140: String[] labels = { "BMW M5", "BMW M3", "Viper GTS-R",
141: "Audi S6" };
142: Paint[] paints = { Color.lightGray, Color.green, Color.blue,
143: Color.red };
144:
145: PieChartDataSet pieChartDataSet = new PieChartDataSet(
146: "Cars That Own", data, labels, paints,
147: pieChart3DProperties);
148: PieChart3D pieChart3D = new PieChart3D(pieChartDataSet, null,
149: new ChartProperties(), 400, 350);
150: super .exportImage(pieChart3D, "pieChart3DLegendLabels");
151: }
152: }
|