1 34 35 package org.krysalis.jcharts.demo.simpleservlet; 36 37 38 import org.krysalis.jcharts.axisChart.AxisChart; 39 import org.krysalis.jcharts.chartData.AxisChartDataSet; 40 import org.krysalis.jcharts.chartData.ChartDataException; 41 import org.krysalis.jcharts.chartData.DataSeries; 42 import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries; 43 import org.krysalis.jcharts.imageMap.ImageMap; 44 import org.krysalis.jcharts.properties.AxisProperties; 45 import org.krysalis.jcharts.properties.BarChartProperties; 46 import org.krysalis.jcharts.properties.ChartProperties; 47 import org.krysalis.jcharts.properties.LegendProperties; 48 import org.krysalis.jcharts.properties.PropertyException; 49 import org.krysalis.jcharts.properties.util.ChartFont; 50 import org.krysalis.jcharts.types.ChartType; 51 52 import javax.servlet.ServletException ; 53 import javax.servlet.http.HttpServlet ; 54 import javax.servlet.http.HttpServletRequest ; 55 import javax.servlet.http.HttpServletResponse ; 56 import java.awt.*; 57 import java.io.IOException ; 58 59 60 65 public class HorizontalBarImageMapServlet extends HttpServlet 66 { 67 private BarChartProperties barChartProperties; 69 70 protected LegendProperties legendProperties; 72 protected AxisProperties axisProperties; 73 protected ChartProperties chartProperties; 74 75 protected int width = 550; 76 protected int height = 360; 77 78 79 82 public void init() 83 { 84 this.legendProperties = new LegendProperties(); 85 this.chartProperties = new ChartProperties(); 86 this.axisProperties = new AxisProperties( true ); 87 ChartFont axisScaleFont = new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 13 ), Color.black ); 88 axisProperties.getXAxisProperties().setScaleChartFont( axisScaleFont ); 89 axisProperties.getYAxisProperties().setScaleChartFont( axisScaleFont ); 90 91 ChartFont axisTitleFont = new ChartFont( new Font( "Arial Narrow", Font.PLAIN, 14 ), Color.black ); 92 axisProperties.getXAxisProperties().setTitleChartFont( axisTitleFont ); 93 axisProperties.getYAxisProperties().setTitleChartFont( axisTitleFont ); 94 95 ChartFont titleFont = new ChartFont( new Font( "Georgia Negreta cursiva", Font.PLAIN, 14 ), Color.black ); 96 this.chartProperties.setTitleFont( titleFont ); 97 98 this.barChartProperties = new BarChartProperties(); 99 } 100 101 102 106 public void service( HttpServletRequest httpServletRequest, 107 HttpServletResponse httpServletResponse ) throws ServletException , IOException 108 { 109 try 110 { 111 String [] xAxisLabels = {"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004"}; 112 String xAxisTitle = "Years"; 113 String yAxisTitle = "Problems"; 114 String title = "Micro$oft At Work"; 115 IAxisDataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); 116 117 double[][] data = new double[][]{{1500, 6880, 4510, 2600, 1200, 1580, 8000, 4555, 4000, 6120}}; 118 String [] legendLabels = {"Bugs"}; 119 Paint[] paints = new Paint[]{Color.blue.darker()}; 120 dataSeries.addIAxisPlotDataSet( new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR, this.barChartProperties ) ); 121 122 AxisChart axisChart = new AxisChart( dataSeries, this.chartProperties, this.axisProperties, this.legendProperties, this.width, this.height ); 123 124 axisChart.renderWithImageMap(); 126 127 ImageMap imageMap = axisChart.getImageMap(); 129 130 httpServletRequest.setAttribute( ChartServlet.IMAGE_MAP, imageMap ); 132 133 httpServletRequest.getSession( true ).setAttribute( ChartServlet.CHART, axisChart ); 135 } 136 catch( ChartDataException chartDataException ) 137 { 138 chartDataException.printStackTrace(); 139 } 140 catch( PropertyException propertyException ) 141 { 142 propertyException.printStackTrace(); 143 } 144 145 146 this.getServletContext().getRequestDispatcher( "/imageMapChart.jsp" ).forward( httpServletRequest, httpServletResponse ); 147 } 148 149 } 150 | Popular Tags |