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.Font;
038: import java.awt.Shape;
039: import java.awt.Stroke;
040:
041: import org.krysalis.jcharts.axisChart.AxisChart;
042: import org.krysalis.jcharts.chartData.DataSeries;
043: import org.krysalis.jcharts.properties.AxisProperties;
044: import org.krysalis.jcharts.properties.ChartProperties;
045: import org.krysalis.jcharts.properties.ClusteredBarChartProperties;
046: import org.krysalis.jcharts.properties.LegendAreaProperties;
047: import org.krysalis.jcharts.properties.LegendProperties;
048: import org.krysalis.jcharts.properties.LineChartProperties;
049: import org.krysalis.jcharts.properties.PointChartProperties;
050: import org.krysalis.jcharts.properties.util.ChartFont;
051: import org.krysalis.jcharts.properties.util.ChartStroke;
052: import org.krysalis.jcharts.types.ChartType;
053:
054: /*************************************************************************************
055: *
056: * @author Nathaniel Auvil
057: * @version $Id: LegendsGuide.java,v 1.6 2003/08/08 08:51:27 nicolaken Exp $
058: ************************************************************************************/
059: public class LegendsGuide extends UserGuideBase {
060:
061: /*****************************************************************************************
062: * Tests a 'real' data set and usage.
063: *
064: * @throws Throwable
065: ******************************************************************************************/
066: public void run() throws Throwable {
067: this .basicLegend();
068: this .noLegend();
069: this .rightSide();
070: this .layout();
071:
072: this .fonts();
073: this .backgroundPaint();
074: this .iconBorderPaint();
075: this .borderColor();
076: this .chartPadding();
077: }
078:
079: /*****************************************************************************************
080: *
081: *
082: ******************************************************************************************/
083: private AxisChart getChart(LegendProperties legendProperties)
084: throws Throwable {
085: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
086: "2002", "2003", "2004" };
087: String xAxisTitle = "Years";
088: String yAxisTitle = "Problems";
089: String title = "Micro$oft at Work";
090: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
091: yAxisTitle, title);
092:
093: Stroke[] strokes = new Stroke[] {
094: LineChartProperties.DEFAULT_LINE_STROKE,
095: LineChartProperties.DEFAULT_LINE_STROKE,
096: LineChartProperties.DEFAULT_LINE_STROKE };
097: Shape[] shapes = new Shape[] {
098: PointChartProperties.SHAPE_DIAMOND,
099: PointChartProperties.SHAPE_TRIANGLE,
100: PointChartProperties.SHAPE_CIRCLE };
101: LineChartProperties lineChartProperties = new LineChartProperties(
102: strokes, shapes);
103:
104: String[] legendLabels = new String[] { "Bugs",
105: "Security Holes", "Backdoors" };
106: dataSeries
107: .addIAxisPlotDataSet(AxisChartsGuide
108: .createAxisChartDataSet(ChartType.LINE,
109: lineChartProperties, 3, legendLabels,
110: 200, 5000));
111:
112: ChartProperties chartProperties = new ChartProperties();
113: AxisProperties axisProperties = new AxisProperties();
114:
115: AxisChart axisChart = new AxisChart(dataSeries,
116: chartProperties, axisProperties, legendProperties,
117: AxisChartsGuide.width, AxisChartsGuide.height);
118:
119: return axisChart;
120: }
121:
122: /*************************************************************************************************/
123: private void basicLegend() throws Throwable {
124: LegendProperties legendProperties = new LegendProperties();
125:
126: super .exportImage(this .getChart(legendProperties),
127: "legendBasic");
128: }
129:
130: /*************************************************************************************************/
131: private void noLegend() throws Throwable {
132: LegendProperties legendProperties = null;
133:
134: super .exportImage(this .getChart(legendProperties), "noLegend");
135: }
136:
137: /*************************************************************************************************/
138: private void rightSide() throws Throwable {
139: LegendProperties legendProperties = new LegendProperties();
140: legendProperties.setPlacement(LegendAreaProperties.RIGHT);
141:
142: super .exportImage(this .getChart(legendProperties),
143: "legendOnRight");
144: }
145:
146: /*************************************************************************************************/
147: private void layout() throws Throwable {
148: LegendProperties legendProperties = new LegendProperties();
149: legendProperties.setPlacement(LegendAreaProperties.LEFT);
150: legendProperties.setNumColumns(1);
151:
152: super .exportImage(this .getChart(legendProperties), "oneColumn");
153: }
154:
155: /*************************************************************************************************/
156: private void fonts() throws Throwable {
157: LegendProperties legendProperties = new LegendProperties();
158: legendProperties.setChartFont(new ChartFont(new Font(
159: "Georgia Negreta cursiva", Font.PLAIN, 13), Color.red));
160:
161: super .exportImage(this .getChart(legendProperties),
162: "legendFonts");
163: }
164:
165: /*************************************************************************************************/
166: private void backgroundPaint() throws Throwable {
167: LegendProperties legendProperties = new LegendProperties();
168: legendProperties.setBackgroundPaint(Color.lightGray);
169:
170: super .exportImage(this .getChart(legendProperties),
171: "legendBackgroundPaint");
172: }
173:
174: /*************************************************************************************************/
175: private void iconBorderPaint() throws Throwable {
176: String[] xAxisLabels = { "1998", "1999", "2000", "2001",
177: "2002", "2003", "2004" };
178: String xAxisTitle = "Years";
179: String yAxisTitle = "Problems";
180: String title = "Micro$oft at Work";
181: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
182: yAxisTitle, title);
183:
184: ClusteredBarChartProperties clusteredBarChartProperties = new ClusteredBarChartProperties();
185:
186: String[] legendLabels = new String[] { "Bugs",
187: "Security Holes", "Backdoors" };
188: dataSeries.addIAxisPlotDataSet(AxisChartsGuide
189: .createAxisChartDataSet(ChartType.BAR_CLUSTERED,
190: clusteredBarChartProperties, 3, legendLabels,
191: 200, 5000));
192:
193: ChartProperties chartProperties = new ChartProperties();
194: AxisProperties axisProperties = new AxisProperties();
195:
196: LegendProperties legendProperties = new LegendProperties();
197: legendProperties.setIconBorderPaint(Color.red);
198:
199: AxisChart axisChart = new AxisChart(dataSeries,
200: chartProperties, axisProperties, legendProperties,
201: AxisChartsGuide.width, AxisChartsGuide.height);
202:
203: super .exportImage(axisChart, "iconBorderPaint");
204: }
205:
206: /*************************************************************************************************/
207: private void borderColor() throws Throwable {
208: LegendProperties legendProperties = new LegendProperties();
209:
210: ChartStroke borderStroke = new ChartStroke(
211: new BasicStroke(2.0f), Color.blue);
212: legendProperties.setBorderStroke(borderStroke);
213:
214: super .exportImage(this .getChart(legendProperties),
215: "borderColor");
216: }
217:
218: /*************************************************************************************************/
219: private void chartPadding() throws Throwable {
220: LegendProperties legendProperties = new LegendProperties();
221: legendProperties.setChartPadding(30);
222:
223: super .exportImage(this .getChart(legendProperties),
224: "chartPadding");
225: }
226:
227: }
|