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 org.krysalis.jcharts.properties.PieChart2DProperties;
036: import org.krysalis.jcharts.properties.LegendProperties;
037: import org.krysalis.jcharts.properties.ChartProperties;
038: import org.krysalis.jcharts.properties.util.ChartStroke;
039: import org.krysalis.jcharts.chartData.ChartDataException;
040: import org.krysalis.jcharts.chartData.PieChartDataSet;
041: import org.krysalis.jcharts.nonAxisChart.PieChart2D;
042: import org.krysalis.jcharts.types.PieLabelType;
043:
044: import java.awt.*;
045:
046: /*************************************************************************************
047: *
048: * @author Nathaniel Auvil
049: * @version $Id: PieChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
050: ************************************************************************************/
051: public class PieChartsGuide extends UserGuideBase {
052:
053: /*****************************************************************************************
054: * Tests a 'real' data set and usage.
055: *
056: * @throws Throwable
057: ******************************************************************************************/
058: public void run() throws Throwable {
059: this .basicChart();
060: this .zeroDegreeOffsetChart();
061: this .borderStroke();
062: this .borderPaint();
063:
064: this .pieValueLabels();
065: this .pieLegendLabels();
066: }
067:
068: /******************************************************************************************/
069: private void outputChart(PieChart2DProperties pieChart2DProperties,
070: String name) throws ChartDataException {
071: double[] data = { 81d, 55d, 39d, 20.6d };
072: String[] labels = { "BMW M5", "BMW M3", "Viper GTS-R",
073: "Corvette Z06" };
074: Paint[] paints = { Color.lightGray, Color.green, Color.blue,
075: Color.red };
076:
077: PieChartDataSet pieChartDataSet = new PieChartDataSet(
078: "Cars That Own", data, labels, paints,
079: pieChart2DProperties);
080:
081: PieChart2D pieChart2D = new PieChart2D(pieChartDataSet,
082: new LegendProperties(), new ChartProperties(), 400, 350);
083: super .exportImage(pieChart2D, name);
084: }
085:
086: /******************************************************************************************/
087: private void basicChart() throws Throwable {
088: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
089: this .outputChart(pieChart2DProperties, "pieChartBasic");
090: }
091:
092: /******************************************************************************************/
093: private void zeroDegreeOffsetChart() throws Throwable {
094: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
095: pieChart2DProperties.setZeroDegreeOffset(45f);
096: this .outputChart(pieChart2DProperties, "pieChartZeroOffset");
097: }
098:
099: /******************************************************************************************/
100: private void borderStroke() throws Throwable {
101: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
102: pieChart2DProperties.setBorderChartStroke(new ChartStroke(
103: new BasicStroke(4f), Color.black));
104: this .outputChart(pieChart2DProperties, "pieChartBorderStroke");
105: }
106:
107: /******************************************************************************************/
108: private void borderPaint() throws Throwable {
109: /*
110: PieChart2DProperties pieChart2DProperties= new PieChart2DProperties();
111: pieChart2DProperties.setBorderPaint( Color.gray );
112: this.outputChart( pieChart2DProperties, "pieChartBorderPaint" );
113: */
114: }
115:
116: private void pieValueLabels() throws ChartDataException {
117: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
118: pieChart2DProperties.setPieLabelType(PieLabelType.VALUE_LABELS);
119: this .outputChart(pieChart2DProperties, "pieChartValueLabels");
120: }
121:
122: private void pieLegendLabels() throws ChartDataException {
123: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
124: pieChart2DProperties
125: .setPieLabelType(PieLabelType.LEGEND_LABELS);
126:
127: double[] data = { 81d, 55d, 39d, 20.6d };
128: String[] labels = { "BMW M5", "BMW M3", "Viper GTS-R",
129: "Audi S6" };
130: Paint[] paints = { Color.lightGray, Color.green, Color.blue,
131: Color.red };
132:
133: PieChartDataSet pieChartDataSet = new PieChartDataSet(
134: "Cars That Own", data, labels, paints,
135: pieChart2DProperties);
136: PieChart2D pieChart2D = new PieChart2D(pieChartDataSet, null,
137: new ChartProperties(), 400, 350);
138: super .exportImage(pieChart2D, "pieChartLegendLabels");
139: }
140: }
|