1 2 35 36 package org.krysalis.jcharts.demo.userGuide; 37 38 39 import org.krysalis.jcharts.chartData.ChartDataException; 40 import org.krysalis.jcharts.chartData.DataSeries; 41 import org.krysalis.jcharts.chartData.AxisChartDataSet; 42 import org.krysalis.jcharts.test.TestDataGenerator; 43 import org.krysalis.jcharts.properties.PointChartProperties; 44 import org.krysalis.jcharts.properties.ChartProperties; 45 import org.krysalis.jcharts.properties.AxisProperties; 46 import org.krysalis.jcharts.properties.LegendProperties; 47 import org.krysalis.jcharts.types.ChartType; 48 import org.krysalis.jcharts.axisChart.AxisChart; 49 50 import java.awt.*; 51 52 53 58 public class PointChartsGuide extends AxisChartsGuide 59 { 60 61 62 public PointChartsGuide() throws Throwable 63 { 64 super(); 65 } 66 67 68 73 public void run() throws ChartDataException 74 { 75 this.basicChart(); 76 this.shapes(); 77 this.nullValues(); 78 } 79 80 81 85 private void basicChart() throws ChartDataException 86 { 87 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 88 String xAxisTitle= "Years"; 89 String yAxisTitle= "Problems"; 90 String title= "Micro$oft at Work"; 91 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 92 93 double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 }, { 150, 15, 6, 62, -54, 10, 84 } }; 94 String [] legendLabels= { "Bugs", "Security Holes" }; 95 Paint[] paints= TestDataGenerator.getRandomPaints( 2 ); 96 97 Shape[] shapes= { PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE }; 98 boolean[] fillPointFlags= { true, true }; 99 Paint[] outlinePaints= { Color.black, Color.black }; 100 PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints ); 101 102 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties ); 103 104 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 105 106 ChartProperties chartProperties= new ChartProperties(); 107 AxisProperties axisProperties= new AxisProperties(); 108 LegendProperties legendProperties= new LegendProperties(); 109 110 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 111 112 super.exportImage( axisChart, "basicChart" ); 113 } 114 115 116 117 118 private void shapes() throws ChartDataException 119 { 120 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 121 String xAxisTitle= "Years"; 122 String yAxisTitle= "Problems"; 123 String title= "Micro$oft at Work"; 124 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 125 126 127 double[][] data= TestDataGenerator.getRandomNumbers( 1, 7, 0, 6000 ); 128 String [] legendLabels= { "Bugs" }; 129 Paint[] paints= TestDataGenerator.getRandomPaints( 1 ); 130 131 Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE }; 132 boolean[] fillPointFlags= { false }; 133 Paint[] outlinePaints= { Color.red }; 134 PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints ); 135 136 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties ); 137 138 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 139 140 ChartProperties chartProperties= new ChartProperties(); 141 AxisProperties axisProperties= new AxisProperties(); 142 LegendProperties legendProperties= new LegendProperties(); 143 144 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 145 146 super.exportImage( axisChart, "shapes" ); 147 } 148 149 150 151 private void nullValues() throws ChartDataException 152 { 153 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 154 String xAxisTitle= "Years"; 155 String yAxisTitle= "Problems"; 156 String title= "Micro$oft at Work"; 157 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 158 159 160 double[][] data= TestDataGenerator.getRandomNumbers( 1, 7, 0, 6000 ); 161 data[ 0 ][ 3 ]= Double.NaN; 162 data[ 0 ][ 4 ]= Double.NaN; 163 164 String [] legendLabels= { "Bugs" }; 165 Paint[] paints= TestDataGenerator.getRandomPaints( 1 ); 166 167 Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE }; 168 boolean[] fillPointFlags= { true }; 169 Paint[] outlinePaints= { Color.black }; 170 PointChartProperties pointChartProperties= new PointChartProperties( shapes, fillPointFlags, outlinePaints ); 171 172 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.POINT, pointChartProperties ); 173 174 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 175 176 ChartProperties chartProperties= new ChartProperties(); 177 AxisProperties axisProperties= new AxisProperties(); 178 LegendProperties legendProperties= new LegendProperties(); 179 180 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 181 182 super.exportImage( axisChart, "nullValues" ); 183 } 184 185 } 186 187 | Popular Tags |