KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > demo > userGuide > StockChartsGuide


1
2 /***********************************************************************************************
3  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
4  *
5  * Redistribution and use of this software and associated documentation ("Software"), with or
6  * without modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain copyright statements and notices.
9  * Redistributions must also contain a copy of this document.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
12  * conditions and the following disclaimer in the documentation and/or other materials
13  * provided with the distribution.
14  *
15  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
16  * products derived from this Software without prior written permission of Nathaniel G.
17  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
18  *
19  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
20  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
21  * registered trademark of Nathaniel G. Auvil.
22  *
23  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
24  *
25  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
26  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
34  ************************************************************************************************/

35
36
37 package org.krysalis.jcharts.demo.userGuide;
38
39
40 import org.krysalis.jcharts.chartData.ChartDataException;
41 import org.krysalis.jcharts.chartData.DataSeries;
42 import org.krysalis.jcharts.chartData.StockChartDataSet;
43 import org.krysalis.jcharts.axisChart.AxisChart;
44 import org.krysalis.jcharts.properties.LegendProperties;
45 import org.krysalis.jcharts.properties.AxisProperties;
46 import org.krysalis.jcharts.properties.ChartProperties;
47 import org.krysalis.jcharts.properties.StockChartProperties;
48 import org.krysalis.jcharts.test.TestDataGenerator;
49
50 import java.awt.*;
51
52
53 /*************************************************************************************
54  *
55  * @author Nathaniel Auvil
56  * @version $Id: StockChartsGuide.java,v 1.1 2003/05/31 19:10:28 nathaniel_auvil Exp $
57  ************************************************************************************/

58 public class StockChartsGuide extends AxisChartsGuide
59 {
60
61     /*****************************************************************************************/
62     public StockChartsGuide() throws Throwable JavaDoc
63     {
64         super();
65     }
66
67
68     /*****************************************************************************************
69     *
70     *
71     * @throws ChartDataException
72     ******************************************************************************************/

73     public void run() throws ChartDataException
74     {
75         this.basicChart();
76         this.strokes();
77         this.lineLengths();
78     }
79
80
81     /*****************************************************************************************
82     *
83     *
84     ******************************************************************************************/

85     private void basicChart() throws ChartDataException
86     {
87         String JavaDoc[] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" };
88         String JavaDoc xAxisTitle= "Days";
89         String JavaDoc yAxisTitle= "$$$";
90         String JavaDoc title= "Id Software";
91         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
92
93         int dataSize= xAxisLabels.length;
94       int numberOfDataSets= 1;
95
96
97       StockChartDataSet stockChartDataSet;
98
99         double[] highs= TestDataGenerator.getRandomNumbers( dataSize, 500, 1000 );
100         double[] lows= TestDataGenerator.getRandomNumbers( dataSize, 100, 300 );
101         double[] opens= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
102         double[] closes= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
103
104       StockChartProperties stockChartProperties= new StockChartProperties();
105
106         stockChartDataSet= new StockChartDataSet( highs, "High", lows, "Low", Color.black, stockChartProperties );
107         stockChartDataSet.setOpenValues( opens, "Open", Color.red );
108         stockChartDataSet.setCloseValues( closes, "Close", Color.green );
109
110         dataSeries.addIAxisPlotDataSet( stockChartDataSet );
111
112
113
114         ChartProperties chartProperties= new ChartProperties();
115         AxisProperties axisProperties= new AxisProperties();
116         LegendProperties legendProperties= new LegendProperties();
117
118         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
119
120         super.exportImage( axisChart, "basicChart" );
121     }
122
123
124
125     /*****************************************************************************************
126     *
127     *
128     ******************************************************************************************/

129     private void strokes() throws ChartDataException
130     {
131         String JavaDoc[] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" };
132         String JavaDoc xAxisTitle= "Days";
133         String JavaDoc yAxisTitle= "$$$";
134         String JavaDoc title= "Id Software";
135         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
136
137         int dataSize= xAxisLabels.length;
138       int numberOfDataSets= 1;
139
140
141       StockChartDataSet stockChartDataSet;
142
143         double[] highs= TestDataGenerator.getRandomNumbers( dataSize, 500, 1000 );
144         double[] lows= TestDataGenerator.getRandomNumbers( dataSize, 100, 300 );
145         double[] opens= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
146         double[] closes= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
147
148       StockChartProperties stockChartProperties= new StockChartProperties();
149         stockChartProperties.setHiLowStroke( new BasicStroke( 3.0f ) );
150         stockChartProperties.setCloseStroke( new BasicStroke( 2.5f ) );
151
152         stockChartDataSet= new StockChartDataSet( highs, "High", lows, "Low", Color.black, stockChartProperties );
153         stockChartDataSet.setOpenValues( opens, "Open", Color.red );
154         stockChartDataSet.setCloseValues( closes, "Close", Color.green );
155
156         dataSeries.addIAxisPlotDataSet( stockChartDataSet );
157
158         ChartProperties chartProperties= new ChartProperties();
159         AxisProperties axisProperties= new AxisProperties();
160         LegendProperties legendProperties= new LegendProperties();
161
162         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
163
164         super.exportImage( axisChart, "strokes" );
165     }
166
167
168     /*****************************************************************************************
169     *
170     *
171     ******************************************************************************************/

172     private void lineLengths() throws ChartDataException
173     {
174         String JavaDoc[] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" };
175         String JavaDoc xAxisTitle= "Days";
176         String JavaDoc yAxisTitle= "$$$";
177         String JavaDoc title= "Id Software";
178         DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
179
180         int dataSize= xAxisLabels.length;
181       int numberOfDataSets= 1;
182
183
184       StockChartDataSet stockChartDataSet;
185
186         double[] highs= TestDataGenerator.getRandomNumbers( dataSize, 500, 1000 );
187         double[] lows= TestDataGenerator.getRandomNumbers( dataSize, 100, 300 );
188         double[] opens= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
189         double[] closes= TestDataGenerator.getRandomNumbers( dataSize, 350, 450 );
190
191       StockChartProperties stockChartProperties= new StockChartProperties();
192         stockChartProperties.setOpenPixelLength( 10 );
193         stockChartProperties.setClosePixelLength( 20 );
194
195         stockChartDataSet= new StockChartDataSet( highs, "High", lows, "Low", Color.black, stockChartProperties );
196         stockChartDataSet.setOpenValues( opens, "Open", Color.red );
197         stockChartDataSet.setCloseValues( closes, "Close", Color.green );
198
199         dataSeries.addIAxisPlotDataSet( stockChartDataSet );
200
201         ChartProperties chartProperties= new ChartProperties();
202         AxisProperties axisProperties= new AxisProperties();
203         LegendProperties legendProperties= new LegendProperties();
204
205         AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height );
206
207         super.exportImage( axisChart, "pixelLengths" );
208     }
209
210 }
211
212
Popular Tags