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.axisChart.AxisChart;
036: import org.krysalis.jcharts.chartData.ChartDataException;
037: import org.krysalis.jcharts.chartData.DataSeries;
038: import org.krysalis.jcharts.properties.AreaChartProperties;
039: import org.krysalis.jcharts.properties.AxisProperties;
040: import org.krysalis.jcharts.properties.ChartProperties;
041: import org.krysalis.jcharts.properties.LegendProperties;
042: import org.krysalis.jcharts.properties.util.ChartStroke;
043: import org.krysalis.jcharts.types.ChartType;
044:
045: import java.awt.*;
046:
047: /*************************************************************************************
048: *
049: * @author Nathaniel Auvil
050: * @version $Id: AllChartsGuide.java,v 1.2 2003/06/25 01:40:15 nathaniel_auvil Exp $
051: ************************************************************************************/
052: public class AllChartsGuide extends UserGuideBase {
053: private DataSeries dataSeries;
054:
055: public AllChartsGuide() throws ChartDataException {
056: this .dataSeries = AxisChartsGuide.createDataSeries();
057: this .dataSeries.addIAxisPlotDataSet(AxisChartsGuide
058: .createAxisChartDataSet(ChartType.AREA,
059: new AreaChartProperties(), 200, 5000));
060: }
061:
062: /*****************************************************************************************
063: * Tests a 'real' data set and usage.
064: *
065: * @throws Throwable
066: ******************************************************************************************/
067: public void run() throws Throwable {
068: this .chartTitle();
069: this .chartNoTitle();
070: this .chartTitleWrapping();
071:
072: this .backgroundPaint();
073: this .chartBorder();
074: this .edgePadding();
075: }
076:
077: /********************************************************************************************/
078: private void backgroundPaint() throws Throwable {
079: ChartProperties chartProperties = this .getChartProperties();
080: GradientPaint paint = new GradientPaint(250, 0, Color.white,
081: 250, 800, new Color(0, 255, 255, 220));
082: chartProperties.setBackgroundPaint(paint);
083:
084: AxisProperties axisProperties = new AxisProperties();
085: axisProperties.setXAxisLabelsAreVertical(true);
086: LegendProperties legendProperties = new LegendProperties();
087:
088: AxisChart axisChart = new AxisChart(this .dataSeries,
089: chartProperties, axisProperties, legendProperties,
090: AxisChartsGuide.width, AxisChartsGuide.height);
091:
092: super .exportImage(axisChart, "backgroundPaint");
093: }
094:
095: /*******************************************************************************************/
096: private void chartBorder() throws Throwable {
097: ChartProperties chartProperties = this .getChartProperties();
098:
099: ChartStroke borderStroke = new ChartStroke(
100: new BasicStroke(2.0f), Color.red);
101: chartProperties.setBorderStroke(borderStroke);
102:
103: AxisProperties axisProperties = new AxisProperties();
104: axisProperties.setXAxisLabelsAreVertical(true);
105: LegendProperties legendProperties = new LegendProperties();
106:
107: AxisChart axisChart = new AxisChart(this .dataSeries,
108: chartProperties, axisProperties, legendProperties,
109: AxisChartsGuide.width, AxisChartsGuide.height);
110:
111: super .exportImage(axisChart, "chartBorder");
112: }
113:
114: /********************************************************************************************/
115: private void edgePadding() throws Throwable {
116: ChartProperties chartProperties = this .getChartProperties();
117: chartProperties.setEdgePadding(50f);
118: chartProperties
119: .setBorderStroke(ChartStroke.DEFAULT_CHART_OUTLINE);
120:
121: AxisProperties axisProperties = new AxisProperties();
122: axisProperties.setXAxisLabelsAreVertical(true);
123: LegendProperties legendProperties = new LegendProperties();
124:
125: AxisChart axisChart = new AxisChart(this .dataSeries,
126: chartProperties, axisProperties, legendProperties,
127: AxisChartsGuide.width, AxisChartsGuide.height);
128:
129: super .exportImage(axisChart, "edgePadding");
130: }
131:
132: /********************************************************************************************/
133: private void chartTitle() throws Throwable {
134: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
135: "2002", "2003", "2004" };
136: DataSeries dataSeries = new DataSeries(xAxisLabels, "Years",
137: "Production", "Micro$oft Bug Production");
138: dataSeries.addIAxisPlotDataSet(AxisChartsGuide
139: .createAxisChartDataSet(ChartType.AREA,
140: new AreaChartProperties(), 200, 5000));
141:
142: ChartProperties chartProperties = this .getChartProperties();
143:
144: AxisProperties axisProperties = new AxisProperties();
145: axisProperties.setXAxisLabelsAreVertical(true);
146: LegendProperties legendProperties = new LegendProperties();
147:
148: AxisChart axisChart = new AxisChart(dataSeries,
149: chartProperties, axisProperties, legendProperties,
150: AxisChartsGuide.width, AxisChartsGuide.height);
151:
152: super .exportImage(axisChart, "chartTitle");
153: }
154:
155: /********************************************************************************************/
156: private void chartNoTitle() throws Throwable {
157: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
158: "2002", "2003", "2004" };
159: DataSeries dataSeries = new DataSeries(xAxisLabels, "Years",
160: "Production", null);
161: dataSeries.addIAxisPlotDataSet(AxisChartsGuide
162: .createAxisChartDataSet(ChartType.AREA,
163: new AreaChartProperties(), 200, 5000));
164:
165: ChartProperties chartProperties = this .getChartProperties();
166:
167: AxisProperties axisProperties = new AxisProperties();
168: axisProperties.setXAxisLabelsAreVertical(true);
169: LegendProperties legendProperties = new LegendProperties();
170:
171: AxisChart axisChart = new AxisChart(dataSeries,
172: chartProperties, axisProperties, legendProperties,
173: AxisChartsGuide.width, AxisChartsGuide.height);
174:
175: super .exportImage(axisChart, "chartNoTitle");
176: }
177:
178: /********************************************************************************************/
179: private void chartTitleWrapping() throws Throwable {
180: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
181: "2002", "2003", "2004" };
182: DataSeries dataSeries = new DataSeries(
183: xAxisLabels,
184: "Years",
185: "Production",
186: "The Micro$ofties have been so very, very, very, busy adding Bugs, this title is going to wrap to the next line");
187:
188: dataSeries.addIAxisPlotDataSet(AxisChartsGuide
189: .createAxisChartDataSet(ChartType.AREA,
190: new AreaChartProperties(), 200, 5000));
191:
192: ChartProperties chartProperties = this .getChartProperties();
193:
194: AxisProperties axisProperties = new AxisProperties();
195: axisProperties.setXAxisLabelsAreVertical(true);
196: LegendProperties legendProperties = new LegendProperties();
197:
198: AxisChart axisChart = new AxisChart(dataSeries,
199: chartProperties, axisProperties, legendProperties,
200: AxisChartsGuide.width, AxisChartsGuide.height);
201:
202: super .exportImage(axisChart, "chartTitleWrapping");
203: }
204:
205: /*******************************************************************************************
206: *
207: * @return
208: *****************************************************************************************/
209: private ChartProperties getChartProperties() {
210: ChartProperties chartProperties = new ChartProperties();
211: //chartProperties.setBorderStroke( ChartStroke.DEFAULT_CHART_OUTLINE );
212: chartProperties.setEdgePadding(20);
213: return chartProperties;
214: }
215: }
|