1 39 40 package org.krysalis.jcharts.test; 41 42 43 import java.awt.BasicStroke ; 44 import java.awt.Paint ; 45 import java.awt.Shape ; 46 import java.awt.Stroke ; 47 import java.awt.geom.Point2D ; 48 49 import org.krysalis.jcharts.axisChart.ScatterPlotAxisChart; 50 import org.krysalis.jcharts.chartData.ChartDataException; 51 import org.krysalis.jcharts.chartData.DataSeries; 52 import org.krysalis.jcharts.chartData.ScatterPlotDataSeries; 53 import org.krysalis.jcharts.chartData.ScatterPlotDataSet; 54 import org.krysalis.jcharts.properties.AxisProperties; 55 import org.krysalis.jcharts.properties.ChartProperties; 56 import org.krysalis.jcharts.properties.DataAxisProperties; 57 import org.krysalis.jcharts.properties.LegendProperties; 58 import org.krysalis.jcharts.properties.LineChartProperties; 59 import org.krysalis.jcharts.properties.PointChartProperties; 60 import org.krysalis.jcharts.properties.PropertyException; 61 import org.krysalis.jcharts.properties.ScatterPlotProperties; 62 63 64 69 public class ScatterPlotTestDriver extends AxisChartTestBase 70 { 71 boolean supportsImageMap() 72 { 73 return true; 74 } 75 76 77 82 private ScatterPlotProperties getScatterPlotProperties( int numberOfDataSets ) 83 { 84 Stroke [] strokes = new Stroke [ numberOfDataSets ]; 85 for( int j = 0; j < numberOfDataSets; j++ ) 86 { 87 strokes[ j ] = LineChartProperties.DEFAULT_LINE_STROKE; 88 } 89 strokes[ 0 ] = new BasicStroke ( 3.0f ); 90 91 Shape [] shapes = new Shape [ numberOfDataSets ]; 92 for( int j = 0; j < numberOfDataSets; j++ ) 93 { 94 shapes[ j ] = PointChartProperties.SHAPE_DIAMOND; 95 } 96 shapes[ 0 ] = PointChartProperties.SHAPE_CIRCLE; 97 98 99 return new ScatterPlotProperties( strokes, shapes ); 100 } 101 102 103 114 private ScatterPlotDataSet createScatterPlotDataSet( int numberOfDataSets, 115 int numberOfValuesToCreate, 116 int xMinValue, 117 int xMaxValue, 118 int yMinValue, 119 int yMaxValue ) throws ChartDataException 120 { 121 123 124 Point2D.Double [] points= new Point2D.Double [ 20 ]; 125 for( int x = 0; x < 20; x++ ) 126 { 127 points[ x ]= new Point2D.Double (); 129 points[ x ].setLocation( x, Math.pow( x, 2 ) ); 130 } 131 132 String [] legendLabels = TestDataGenerator.getRandomStrings( 1, 12, false ); 133 Paint paint = TestDataGenerator.getRandomPaint(); 135 136 ScatterPlotDataSet scatterPlotDataSet= new ScatterPlotDataSet( this.getScatterPlotProperties( 1 ) ); 137 scatterPlotDataSet.addDataPoints( points, paint, legendLabels[ 0 ] ); 138 139 System.out.println( "legendLabels[ 0 ]= " + legendLabels[ 0 ] ); 140 return scatterPlotDataSet; 141 } 142 143 144 148 DataSeries getDataSeries() throws ChartDataException 149 { 150 DataSeries dataSeries= null; 151 152 int dataSize = (int) TestDataGenerator.getRandomNumber( 3, 3 ); 153 int numberOfDataSets = (int) TestDataGenerator.getRandomNumber( 1, 1 ); 154 155 157 String xAxisTitle = TestDataGenerator.getRandomString( 15, true ); 159 String yAxisTitle = TestDataGenerator.getRandomString( 15, true ); 160 162 163 165 return dataSeries; 166 } 167 168 169 198 199 200 public static void main( String [] args ) throws ChartDataException, PropertyException 201 { 202 ScatterPlotTestDriver s= new ScatterPlotTestDriver(); 203 204 ScatterPlotDataSet scatterPlotDataSet= s.createScatterPlotDataSet( 1, 5, -1000, 3000, 200, 500 ); 205 ScatterPlotDataSeries scatterPlotDataSeries = new ScatterPlotDataSeries( scatterPlotDataSet, 206 "X-Axis Title", 207 "Y-Axis Title", 208 "Chart Title" ); 209 210 DataAxisProperties xAxisProperties= new DataAxisProperties(); 211 xAxisProperties.setUserDefinedScale( -5, 3 ); 212 xAxisProperties.setNumItems( 10 ); 213 xAxisProperties.setRoundToNearest( 0 ); 214 215 DataAxisProperties yAxisProperties= new DataAxisProperties(); 216 yAxisProperties.setUserDefinedScale( -30, 50 ); 217 yAxisProperties.setNumItems( 10 ); 218 yAxisProperties.setRoundToNearest( 1 ); 219 220 AxisProperties axisProperties = new AxisProperties( xAxisProperties, yAxisProperties ); 221 ChartProperties chartProperties = new ChartProperties(); 222 LegendProperties legendProperties = new LegendProperties(); 223 224 ScatterPlotAxisChart scatterPlotAxisChart = new ScatterPlotAxisChart( scatterPlotDataSeries, 225 chartProperties, 226 axisProperties, 227 legendProperties, 228 500, 229 400 ); 230 231 ChartTestDriver.exportImage( scatterPlotAxisChart, "ScatterPlotTest.png" ); 232 } 233 234 235 } 236 | Popular Tags |