1 34 35 package org.krysalis.jcharts.demo.userGuide; 36 37 import org.krysalis.jcharts.chartData.ChartDataException; 38 import org.krysalis.jcharts.chartData.DataSeries; 39 import org.krysalis.jcharts.chartData.AxisChartDataSet; 40 import org.krysalis.jcharts.test.TestDataGenerator; 41 import org.krysalis.jcharts.properties.LineChartProperties; 42 import org.krysalis.jcharts.properties.PointChartProperties; 43 import org.krysalis.jcharts.properties.LegendProperties; 44 import org.krysalis.jcharts.properties.AxisProperties; 45 import org.krysalis.jcharts.properties.ChartProperties; 46 import org.krysalis.jcharts.types.ChartType; 47 import org.krysalis.jcharts.axisChart.AxisChart; 48 49 import java.awt.*; 50 51 52 53 58 public class LineChartsGuide extends AxisChartsGuide 59 { 60 61 62 67 public void run() throws ChartDataException 68 { 69 this.basicChart(); 70 this.strokes(); 71 this.missingValues(); 72 } 73 74 75 76 77 private void basicChart() throws ChartDataException 78 { 79 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 80 String xAxisTitle= "Years"; 81 String yAxisTitle= "Problems"; 82 String title= "Micro$oft at Work"; 83 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 84 85 double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } }; 86 String [] legendLabels= { "Bugs" }; 87 Paint[] paints= TestDataGenerator.getRandomPaints( 1 ); 88 89 Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE }; 90 Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE }; 91 LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes ); 92 93 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties ); 94 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 95 96 ChartProperties chartProperties= new ChartProperties(); 97 AxisProperties axisProperties= new AxisProperties(); 98 LegendProperties legendProperties= new LegendProperties(); 99 100 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 101 102 super.exportImage( axisChart, "basicChart" ); 103 } 104 105 106 107 private void strokes() throws ChartDataException 108 { 109 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 110 String xAxisTitle= "Years"; 111 String yAxisTitle= "Problems"; 112 String title= "Micro$oft at Work"; 113 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 114 115 double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 }, { 150, 15, 6, 62, -54, 10, 84 } }; 116 String [] legendLabels= { "Bugs", "Security Holes" }; 117 Paint[] paints= TestDataGenerator.getRandomPaints( 2 ); 118 119 Stroke[] strokes= new Stroke[ 2 ]; 120 strokes[ 0 ]= new BasicStroke( 3.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f, new float[]{ 5f, 5f, 10f, 5f}, 4f ); 121 strokes[ 1 ]= new BasicStroke( 5.0f ); 122 Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE, null }; 123 LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes ); 124 125 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties ); 126 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 127 128 ChartProperties chartProperties= new ChartProperties(); 129 AxisProperties axisProperties= new AxisProperties(); 130 LegendProperties legendProperties= new LegendProperties(); 131 132 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 133 134 super.exportImage( axisChart, "strokes" ); 135 } 136 137 138 139 140 private void missingValues() throws ChartDataException 141 { 142 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 143 String xAxisTitle= "Years"; 144 String yAxisTitle= "Problems"; 145 String title= "Micro$oft at Work"; 146 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 147 148 double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } }; 149 data[ 0 ][ 3 ]= Double.NaN; 150 data[ 0 ][ 4 ]= Double.NaN; 151 152 String [] legendLabels= { "Bugs" }; 153 Paint[] paints= TestDataGenerator.getRandomPaints( 1 ); 154 155 Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE }; 156 Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE }; 157 LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes ); 158 159 AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, ChartType.LINE, lineChartProperties ); 160 161 dataSeries.addIAxisPlotDataSet( axisChartDataSet ); 162 163 ChartProperties chartProperties= new ChartProperties(); 164 AxisProperties axisProperties= new AxisProperties(); 165 LegendProperties legendProperties= new LegendProperties(); 166 167 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 168 169 super.exportImage( axisChart, "missingValues" ); 170 } 171 } 172 173 | Popular Tags |