| 1 34 35 package org.krysalis.jcharts.demo.userGuide; 36 37 import java.awt.BasicStroke ; 38 import java.awt.Color ; 39 import java.awt.Font ; 40 import java.awt.Shape ; 41 import java.awt.Stroke ; 42 43 import org.krysalis.jcharts.axisChart.AxisChart; 44 import org.krysalis.jcharts.chartData.DataSeries; 45 import org.krysalis.jcharts.properties.AxisProperties; 46 import org.krysalis.jcharts.properties.ChartProperties; 47 import org.krysalis.jcharts.properties.ClusteredBarChartProperties; 48 import org.krysalis.jcharts.properties.LegendAreaProperties; 49 import org.krysalis.jcharts.properties.LegendProperties; 50 import org.krysalis.jcharts.properties.LineChartProperties; 51 import org.krysalis.jcharts.properties.PointChartProperties; 52 import org.krysalis.jcharts.properties.util.ChartFont; 53 import org.krysalis.jcharts.properties.util.ChartStroke; 54 import org.krysalis.jcharts.types.ChartType; 55 56 57 62 public class LegendsGuide extends UserGuideBase 63 { 64 65 70 public void run() throws Throwable  71 { 72 this.basicLegend(); 73 this.noLegend(); 74 this.rightSide(); 75 this.layout(); 76 77 this.fonts(); 78 this.backgroundPaint(); 79 this.iconBorderPaint(); 80 this.borderColor(); 81 this.chartPadding(); 82 } 83 84 85 89 private AxisChart getChart( LegendProperties legendProperties ) throws Throwable  90 { 91 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 92 String xAxisTitle= "Years"; 93 String yAxisTitle= "Problems"; 94 String title= "Micro$oft at Work"; 95 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 96 97 Stroke [] strokes = new Stroke []{ LineChartProperties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE }; 98 Shape [] shapes = new Shape []{ PointChartProperties.SHAPE_DIAMOND, PointChartProperties.SHAPE_TRIANGLE, PointChartProperties.SHAPE_CIRCLE }; 99 LineChartProperties lineChartProperties= new LineChartProperties( strokes, shapes ); 100 101 String [] legendLabels= new String []{ "Bugs", "Security Holes", "Backdoors" }; 102 dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.LINE, lineChartProperties, 3, legendLabels, 200, 5000 ) ); 103 104 ChartProperties chartProperties= new ChartProperties(); 105 AxisProperties axisProperties= new AxisProperties(); 106 107 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 108 109 return axisChart; 110 } 111 112 113 114 private void basicLegend() throws Throwable  115 { 116 LegendProperties legendProperties= new LegendProperties(); 117 118 super.exportImage( this.getChart( legendProperties ), "legendBasic" ); 119 } 120 121 122 123 private void noLegend() throws Throwable  124 { 125 LegendProperties legendProperties= null; 126 127 super.exportImage( this.getChart( legendProperties ), "noLegend" ); 128 } 129 130 131 132 private void rightSide() throws Throwable  133 { 134 LegendProperties legendProperties= new LegendProperties(); 135 legendProperties.setPlacement( LegendAreaProperties.RIGHT ); 136 137 super.exportImage( this.getChart( legendProperties ), "legendOnRight" ); 138 } 139 140 141 142 private void layout() throws Throwable  143 { 144 LegendProperties legendProperties= new LegendProperties(); 145 legendProperties.setPlacement( LegendAreaProperties.LEFT ); 146 legendProperties.setNumColumns( 1 ); 147 148 super.exportImage( this.getChart( legendProperties ), "oneColumn" ); 149 } 150 151 152 153 154 private void fonts() throws Throwable  155 { 156 LegendProperties legendProperties= new LegendProperties(); 157 legendProperties.setChartFont( new ChartFont( new Font ( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.red ) ); 158 159 super.exportImage( this.getChart( legendProperties ), "legendFonts" ); 160 } 161 162 163 164 private void backgroundPaint() throws Throwable  165 { 166 LegendProperties legendProperties= new LegendProperties(); 167 legendProperties.setBackgroundPaint( Color.lightGray ); 168 169 super.exportImage( this.getChart( legendProperties ), "legendBackgroundPaint" ); 170 } 171 172 173 174 175 private void iconBorderPaint() throws Throwable  176 { 177 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 178 String xAxisTitle= "Years"; 179 String yAxisTitle= "Problems"; 180 String title= "Micro$oft at Work"; 181 DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 182 183 ClusteredBarChartProperties clusteredBarChartProperties= new ClusteredBarChartProperties(); 184 185 String [] legendLabels= new String []{ "Bugs", "Security Holes", "Backdoors" }; 186 dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.BAR_CLUSTERED, clusteredBarChartProperties, 3, legendLabels, 200, 5000 ) ); 187 188 ChartProperties chartProperties= new ChartProperties(); 189 AxisProperties axisProperties= new AxisProperties(); 190 191 LegendProperties legendProperties= new LegendProperties(); 192 legendProperties.setIconBorderPaint( Color.red ); 193 194 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 195 196 super.exportImage( axisChart, "iconBorderPaint" ); 197 } 198 199 200 201 private void borderColor() throws Throwable  202 { 203 LegendProperties legendProperties= new LegendProperties(); 204 205 ChartStroke borderStroke= new ChartStroke( new BasicStroke ( 2.0f ), Color.blue ); 206 legendProperties.setBorderStroke( borderStroke ); 207 208 super.exportImage( this.getChart( legendProperties ), "borderColor" ); 209 } 210 211 212 213 private void chartPadding() throws Throwable  214 { 215 LegendProperties legendProperties= new LegendProperties(); 216 legendProperties.setChartPadding( 30 ); 217 218 super.exportImage( this.getChart( legendProperties ), "chartPadding" ); 219 } 220 221 } 222 223 224 225 226 227 | Popular Tags |