1 2 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 58 public class StockChartsGuide extends AxisChartsGuide 59 { 60 61 62 public StockChartsGuide() throws Throwable 63 { 64 super(); 65 } 66 67 68 73 public void run() throws ChartDataException 74 { 75 this.basicChart(); 76 this.strokes(); 77 this.lineLengths(); 78 } 79 80 81 85 private void basicChart() throws ChartDataException 86 { 87 String [] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" }; 88 String xAxisTitle= "Days"; 89 String yAxisTitle= "$$$"; 90 String 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 129 private void strokes() throws ChartDataException 130 { 131 String [] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" }; 132 String xAxisTitle= "Days"; 133 String yAxisTitle= "$$$"; 134 String 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 172 private void lineLengths() throws ChartDataException 173 { 174 String [] xAxisLabels= { "June 2", "June 3", "June 4", "June 5", "June 6", "June 7", "June 8" }; 175 String xAxisTitle= "Days"; 176 String yAxisTitle= "$$$"; 177 String 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 |