1 2 35 36 package org.krysalis.jcharts.demo.userGuide; 37 38 39 import org.krysalis.jcharts.axisChart.AxisChart; 40 import org.krysalis.jcharts.chartData.ChartDataException; 41 import org.krysalis.jcharts.chartData.DataSeries; 42 import org.krysalis.jcharts.properties.AreaChartProperties; 43 import org.krysalis.jcharts.properties.AxisProperties; 44 import org.krysalis.jcharts.properties.ChartProperties; 45 import org.krysalis.jcharts.properties.LegendProperties; 46 import org.krysalis.jcharts.properties.util.ChartStroke; 47 import org.krysalis.jcharts.types.ChartType; 48 49 import java.awt.*; 50 51 52 57 public class AllChartsGuide extends UserGuideBase 58 { 59 private DataSeries dataSeries; 60 61 62 63 public AllChartsGuide() throws ChartDataException 64 { 65 this.dataSeries= AxisChartsGuide.createDataSeries(); 66 this.dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) ); 67 } 68 69 70 75 public void run() throws Throwable 76 { 77 this.chartTitle(); 78 this.chartNoTitle(); 79 this.chartTitleWrapping(); 80 81 this.backgroundPaint(); 82 this.chartBorder(); 83 this.edgePadding(); 84 } 85 86 87 88 private void backgroundPaint() throws Throwable 89 { 90 ChartProperties chartProperties= this.getChartProperties(); 91 GradientPaint paint= new GradientPaint( 250, 0, Color.white, 92 250, 800, new Color( 0, 255, 255, 220 ) ); 93 chartProperties.setBackgroundPaint( paint ); 94 95 AxisProperties axisProperties= new AxisProperties(); 96 axisProperties.setXAxisLabelsAreVertical( true ); 97 LegendProperties legendProperties= new LegendProperties(); 98 99 AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 100 101 super.exportImage( axisChart, "backgroundPaint" ); 102 } 103 104 105 106 private void chartBorder() throws Throwable 107 { 108 ChartProperties chartProperties= this.getChartProperties(); 109 110 ChartStroke borderStroke= new ChartStroke( new BasicStroke( 2.0f ), Color.red ); 111 chartProperties.setBorderStroke( borderStroke ); 112 113 AxisProperties axisProperties= new AxisProperties(); 114 axisProperties.setXAxisLabelsAreVertical( true ); 115 LegendProperties legendProperties= new LegendProperties(); 116 117 AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 118 119 super.exportImage( axisChart, "chartBorder" ); 120 } 121 122 123 124 private void edgePadding() throws Throwable 125 { 126 ChartProperties chartProperties= this.getChartProperties(); 127 chartProperties.setEdgePadding( 50f ); 128 chartProperties.setBorderStroke( ChartStroke.DEFAULT_CHART_OUTLINE ); 129 130 AxisProperties axisProperties= new AxisProperties(); 131 axisProperties.setXAxisLabelsAreVertical( true ); 132 LegendProperties legendProperties= new LegendProperties(); 133 134 AxisChart axisChart= new AxisChart( this.dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 135 136 137 super.exportImage( axisChart, "edgePadding" ); 138 } 139 140 141 142 private void chartTitle() throws Throwable 143 { 144 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 145 DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", "Micro$oft Bug Production" ); 146 dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) ); 147 148 ChartProperties chartProperties= this.getChartProperties(); 149 150 AxisProperties axisProperties= new AxisProperties(); 151 axisProperties.setXAxisLabelsAreVertical( true ); 152 LegendProperties legendProperties= new LegendProperties(); 153 154 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 155 156 super.exportImage( axisChart, "chartTitle" ); 157 } 158 159 160 private void chartNoTitle() throws Throwable 161 { 162 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 163 DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", null ); 164 dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) ); 165 166 ChartProperties chartProperties= this.getChartProperties(); 167 168 AxisProperties axisProperties= new AxisProperties(); 169 axisProperties.setXAxisLabelsAreVertical( true ); 170 LegendProperties legendProperties= new LegendProperties(); 171 172 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 173 174 super.exportImage( axisChart, "chartNoTitle" ); 175 } 176 177 178 179 private void chartTitleWrapping() throws Throwable 180 { 181 String [] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; 182 DataSeries dataSeries = new DataSeries( xAxisLabels, "Years", "Production", "The Micro$ofties have been so very, very, very, busy adding Bugs, this title is going to wrap to the next line" ); 183 184 dataSeries.addIAxisPlotDataSet( AxisChartsGuide.createAxisChartDataSet( ChartType.AREA, new AreaChartProperties(), 200, 5000 ) ); 185 186 ChartProperties chartProperties= this.getChartProperties(); 187 188 AxisProperties axisProperties= new AxisProperties(); 189 axisProperties.setXAxisLabelsAreVertical( true ); 190 LegendProperties legendProperties= new LegendProperties(); 191 192 AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, legendProperties, AxisChartsGuide.width, AxisChartsGuide.height ); 193 194 super.exportImage( axisChart, "chartTitleWrapping" ); 195 } 196 197 198 202 private ChartProperties getChartProperties() 203 { 204 ChartProperties chartProperties= new ChartProperties(); 205 chartProperties.setEdgePadding( 20 ); 207 return chartProperties; 208 } 209 } 210 211 212 213 214 215 | Popular Tags |