1 48 49 package org.krysalis.jcharts.demo.simpleservlet; 50 51 52 import org.krysalis.jcharts.properties.LineChartProperties; 53 import org.krysalis.jcharts.properties.BarChartProperties; 54 import org.krysalis.jcharts.properties.LegendProperties; 55 import org.krysalis.jcharts.properties.AxisProperties; 56 import org.krysalis.jcharts.properties.ChartProperties; 57 import org.krysalis.jcharts.properties.PointChartProperties; 58 import org.krysalis.jcharts.properties.util.ChartFont; 59 import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries; 60 import org.krysalis.jcharts.chartData.DataSeries; 61 import org.krysalis.jcharts.chartData.AxisChartDataSet; 62 import org.krysalis.jcharts.types.ChartType; 63 import org.krysalis.jcharts.axisChart.AxisChart; 64 import org.krysalis.jcharts.encoders.ServletEncoderHelper; 65 66 import javax.servlet.ServletException ; 67 import javax.servlet.http.*; 68 import java.awt.*; 69 import java.io.IOException ; 70 71 72 public class ComboChartServlet extends HttpServlet 73 { 74 private LineChartProperties lineChartProperties; 76 77 private BarChartProperties barChartProperties; 79 80 protected LegendProperties legendProperties; 82 protected AxisProperties axisProperties; 83 protected ChartProperties chartProperties; 84 85 protected int width = 550; 86 protected int height = 360; 87 88 89 92 public void init() 93 { 94 this.legendProperties = new LegendProperties(); 95 this.chartProperties = new ChartProperties(); 96 this.axisProperties = new AxisProperties( false ); 97 ChartFont axisScaleFont = new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.black ); 98 axisProperties.getXAxisProperties().setScaleChartFont( axisScaleFont ); 99 axisProperties.getYAxisProperties().setScaleChartFont( axisScaleFont ); 100 101 ChartFont axisTitleFont = new ChartFont( new Font( "Arial Narrow", Font.PLAIN, 14 ), Color.black ); 102 axisProperties.getXAxisProperties().setTitleChartFont( axisTitleFont ); 103 axisProperties.getYAxisProperties().setTitleChartFont( axisTitleFont ); 104 105 ChartFont titleFont = new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 14 ), Color.black ); 106 this.chartProperties.setTitleFont( titleFont ); 107 108 109 Stroke[] strokes = {LineChartProperties.DEFAULT_LINE_STROKE}; 110 Shape[] shapes = {PointChartProperties.SHAPE_DIAMOND}; 111 this.lineChartProperties = new LineChartProperties( strokes, shapes ); 112 113 this.barChartProperties = new BarChartProperties(); 114 } 115 116 117 120 public void service( HttpServletRequest req, HttpServletResponse httpServletResponse ) throws ServletException , IOException 121 { 122 try 123 { 124 String [] xAxisLabels = {"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004"}; 125 String xAxisTitle = "Years"; 126 String yAxisTitle = "Problems"; 127 String title = "Micro$oft At Work"; 128 IAxisDataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 129 130 double[][] data = new double[][]{{1500, 6880, 4510, 2600, 1200, 1580, 8000, 4555, 4000, 6120}}; 131 String [] legendLabels = {"Bugs"}; 132 Paint[] paints = new Paint[]{Color.blue.darker()}; 133 Paint[] linePaints = new Paint[]{Color.green}; 134 dataSeries.addIAxisPlotDataSet( new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR, this.barChartProperties ) ); 135 dataSeries.addIAxisPlotDataSet( new AxisChartDataSet( data, legendLabels, linePaints, ChartType.LINE, this.lineChartProperties ) ); 136 137 AxisChart axisChart = new AxisChart( dataSeries, this.chartProperties, this.axisProperties, this.legendProperties, this.width, this.height ); 138 ServletEncoderHelper.encodeJPEG13( axisChart, 1.0f, httpServletResponse ); 139 } 140 catch( Throwable throwable ) 141 { 142 throwable.printStackTrace(); 144 } 145 } 146 } 147 | Popular Tags |