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.chartData.ChartDataException;
036: import org.krysalis.jcharts.chartData.DataSeries;
037: import org.krysalis.jcharts.chartData.StockChartDataSet;
038: import org.krysalis.jcharts.axisChart.AxisChart;
039: import org.krysalis.jcharts.properties.LegendProperties;
040: import org.krysalis.jcharts.properties.AxisProperties;
041: import org.krysalis.jcharts.properties.ChartProperties;
042: import org.krysalis.jcharts.properties.StockChartProperties;
043: import org.krysalis.jcharts.test.TestDataGenerator;
044:
045: import java.awt.*;
046:
047: /*************************************************************************************
048: *
049: * @author Nathaniel Auvil
050: * @version $Id: StockChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
051: ************************************************************************************/
052: public class StockChartsGuide extends AxisChartsGuide {
053:
054: /*****************************************************************************************/
055: public StockChartsGuide() throws Throwable {
056: super ();
057: }
058:
059: /*****************************************************************************************
060: *
061: *
062: * @throws ChartDataException
063: ******************************************************************************************/
064: public void run() throws ChartDataException {
065: this .basicChart();
066: this .strokes();
067: this .lineLengths();
068: }
069:
070: /*****************************************************************************************
071: *
072: *
073: ******************************************************************************************/
074: private void basicChart() throws ChartDataException {
075: String[] xAxisLabels = { "June 2", "June 3", "June 4",
076: "June 5", "June 6", "June 7", "June 8" };
077: String xAxisTitle = "Days";
078: String yAxisTitle = "$$$";
079: String title = "Id Software";
080: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
081: yAxisTitle, title);
082:
083: int dataSize = xAxisLabels.length;
084: int numberOfDataSets = 1;
085:
086: StockChartDataSet stockChartDataSet;
087:
088: double[] highs = TestDataGenerator.getRandomNumbers(dataSize,
089: 500, 1000);
090: double[] lows = TestDataGenerator.getRandomNumbers(dataSize,
091: 100, 300);
092: double[] opens = TestDataGenerator.getRandomNumbers(dataSize,
093: 350, 450);
094: double[] closes = TestDataGenerator.getRandomNumbers(dataSize,
095: 350, 450);
096:
097: StockChartProperties stockChartProperties = new StockChartProperties();
098:
099: stockChartDataSet = new StockChartDataSet(highs, "High", lows,
100: "Low", Color.black, stockChartProperties);
101: stockChartDataSet.setOpenValues(opens, "Open", Color.red);
102: stockChartDataSet.setCloseValues(closes, "Close", Color.green);
103:
104: dataSeries.addIAxisPlotDataSet(stockChartDataSet);
105:
106: ChartProperties chartProperties = new ChartProperties();
107: AxisProperties axisProperties = new AxisProperties();
108: LegendProperties legendProperties = new LegendProperties();
109:
110: AxisChart axisChart = new AxisChart(dataSeries,
111: chartProperties, axisProperties, legendProperties,
112: AxisChartsGuide.width, AxisChartsGuide.height);
113:
114: super .exportImage(axisChart, "basicChart");
115: }
116:
117: /*****************************************************************************************
118: *
119: *
120: ******************************************************************************************/
121: private void strokes() throws ChartDataException {
122: String[] xAxisLabels = { "June 2", "June 3", "June 4",
123: "June 5", "June 6", "June 7", "June 8" };
124: String xAxisTitle = "Days";
125: String yAxisTitle = "$$$";
126: String title = "Id Software";
127: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
128: yAxisTitle, title);
129:
130: int dataSize = xAxisLabels.length;
131: int numberOfDataSets = 1;
132:
133: StockChartDataSet stockChartDataSet;
134:
135: double[] highs = TestDataGenerator.getRandomNumbers(dataSize,
136: 500, 1000);
137: double[] lows = TestDataGenerator.getRandomNumbers(dataSize,
138: 100, 300);
139: double[] opens = TestDataGenerator.getRandomNumbers(dataSize,
140: 350, 450);
141: double[] closes = TestDataGenerator.getRandomNumbers(dataSize,
142: 350, 450);
143:
144: StockChartProperties stockChartProperties = new StockChartProperties();
145: stockChartProperties.setHiLowStroke(new BasicStroke(3.0f));
146: stockChartProperties.setCloseStroke(new BasicStroke(2.5f));
147:
148: stockChartDataSet = new StockChartDataSet(highs, "High", lows,
149: "Low", Color.black, stockChartProperties);
150: stockChartDataSet.setOpenValues(opens, "Open", Color.red);
151: stockChartDataSet.setCloseValues(closes, "Close", Color.green);
152:
153: dataSeries.addIAxisPlotDataSet(stockChartDataSet);
154:
155: ChartProperties chartProperties = new ChartProperties();
156: AxisProperties axisProperties = new AxisProperties();
157: LegendProperties legendProperties = new LegendProperties();
158:
159: AxisChart axisChart = new AxisChart(dataSeries,
160: chartProperties, axisProperties, legendProperties,
161: AxisChartsGuide.width, AxisChartsGuide.height);
162:
163: super .exportImage(axisChart, "strokes");
164: }
165:
166: /*****************************************************************************************
167: *
168: *
169: ******************************************************************************************/
170: private void lineLengths() throws ChartDataException {
171: String[] xAxisLabels = { "June 2", "June 3", "June 4",
172: "June 5", "June 6", "June 7", "June 8" };
173: String xAxisTitle = "Days";
174: String yAxisTitle = "$$$";
175: String title = "Id Software";
176: DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
177: yAxisTitle, title);
178:
179: int dataSize = xAxisLabels.length;
180: int numberOfDataSets = 1;
181:
182: StockChartDataSet stockChartDataSet;
183:
184: double[] highs = TestDataGenerator.getRandomNumbers(dataSize,
185: 500, 1000);
186: double[] lows = TestDataGenerator.getRandomNumbers(dataSize,
187: 100, 300);
188: double[] opens = TestDataGenerator.getRandomNumbers(dataSize,
189: 350, 450);
190: double[] closes = TestDataGenerator.getRandomNumbers(dataSize,
191: 350, 450);
192:
193: StockChartProperties stockChartProperties = new StockChartProperties();
194: stockChartProperties.setOpenPixelLength(10);
195: stockChartProperties.setClosePixelLength(20);
196:
197: stockChartDataSet = new StockChartDataSet(highs, "High", lows,
198: "Low", Color.black, stockChartProperties);
199: stockChartDataSet.setOpenValues(opens, "Open", Color.red);
200: stockChartDataSet.setCloseValues(closes, "Close", Color.green);
201:
202: dataSeries.addIAxisPlotDataSet(stockChartDataSet);
203:
204: ChartProperties chartProperties = new ChartProperties();
205: AxisProperties axisProperties = new AxisProperties();
206: LegendProperties legendProperties = new LegendProperties();
207:
208: AxisChart axisChart = new AxisChart(dataSeries,
209: chartProperties, axisProperties, legendProperties,
210: AxisChartsGuide.width, AxisChartsGuide.height);
211:
212: super .exportImage(axisChart, "pixelLengths");
213: }
214:
215: }
|