001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.demo.simpleservlet;
034:
035: import org.krysalis.jcharts.axisChart.AxisChart;
036: import org.krysalis.jcharts.chartData.AxisChartDataSet;
037: import org.krysalis.jcharts.chartData.ChartDataException;
038: import org.krysalis.jcharts.chartData.DataSeries;
039: import org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries;
040: import org.krysalis.jcharts.imageMap.ImageMap;
041: import org.krysalis.jcharts.properties.AxisProperties;
042: import org.krysalis.jcharts.properties.BarChartProperties;
043: import org.krysalis.jcharts.properties.ChartProperties;
044: import org.krysalis.jcharts.properties.LegendProperties;
045: import org.krysalis.jcharts.properties.PropertyException;
046: import org.krysalis.jcharts.properties.util.ChartFont;
047: import org.krysalis.jcharts.types.ChartType;
048:
049: import javax.servlet.ServletException;
050: import javax.servlet.http.HttpServlet;
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053: import java.awt.*;
054: import java.io.IOException;
055:
056: /*************************************************************************************
057: *
058: * @author Nathaniel Auvil
059: * @version $Id: HorizontalBarImageMapServlet.java,v 1.1 2003/08/28 01:17:36 nathaniel_auvil Exp $
060: ************************************************************************************/
061: public class HorizontalBarImageMapServlet extends HttpServlet {
062: //---all of my charts serviced by this Servlet will have the same properties.
063: private BarChartProperties barChartProperties;
064:
065: //---all of my charts serviced by this Servlet will have the same properties.
066: protected LegendProperties legendProperties;
067: protected AxisProperties axisProperties;
068: protected ChartProperties chartProperties;
069:
070: protected int width = 550;
071: protected int height = 360;
072:
073: /**********************************************************************************************
074: *
075: **********************************************************************************************/
076: public void init() {
077: this .legendProperties = new LegendProperties();
078: this .chartProperties = new ChartProperties();
079: this .axisProperties = new AxisProperties(true);
080: ChartFont axisScaleFont = new ChartFont(new Font(
081: "Georgia Negreta cursiva", Font.PLAIN, 13), Color.black);
082: axisProperties.getXAxisProperties().setScaleChartFont(
083: axisScaleFont);
084: axisProperties.getYAxisProperties().setScaleChartFont(
085: axisScaleFont);
086:
087: ChartFont axisTitleFont = new ChartFont(new Font(
088: "Arial Narrow", Font.PLAIN, 14), Color.black);
089: axisProperties.getXAxisProperties().setTitleChartFont(
090: axisTitleFont);
091: axisProperties.getYAxisProperties().setTitleChartFont(
092: axisTitleFont);
093:
094: ChartFont titleFont = new ChartFont(new Font(
095: "Georgia Negreta cursiva", Font.PLAIN, 14), Color.black);
096: this .chartProperties.setTitleFont(titleFont);
097:
098: this .barChartProperties = new BarChartProperties();
099: }
100:
101: /**********************************************************************************************
102: *
103: *
104: **********************************************************************************************/
105: public void service(HttpServletRequest httpServletRequest,
106: HttpServletResponse httpServletResponse)
107: throws ServletException, IOException {
108: try {
109: String[] xAxisLabels = { "1995", "1996", "1997", "1998",
110: "1999", "2000", "2001", "2002", "2003", "2004" };
111: String xAxisTitle = "Years";
112: String yAxisTitle = "Problems";
113: String title = "Micro$oft At Work";
114: IAxisDataSeries dataSeries = new DataSeries(xAxisLabels,
115: xAxisTitle, yAxisTitle, title);
116:
117: double[][] data = new double[][] { { 1500, 6880, 4510,
118: 2600, 1200, 1580, 8000, 4555, 4000, 6120 } };
119: String[] legendLabels = { "Bugs" };
120: Paint[] paints = new Paint[] { Color.blue.darker() };
121: dataSeries.addIAxisPlotDataSet(new AxisChartDataSet(data,
122: legendLabels, paints, ChartType.BAR,
123: this .barChartProperties));
124:
125: AxisChart axisChart = new AxisChart(dataSeries,
126: this .chartProperties, this .axisProperties,
127: this .legendProperties, this .width, this .height);
128:
129: //---this call will render the chart to an internal BufferedImage, creating all the image map coordinates
130: axisChart.renderWithImageMap();
131:
132: //---get the ImageMap information from the chart
133: ImageMap imageMap = axisChart.getImageMap();
134:
135: //---set the ImageMap into the HttpServletRequest so can get it out in JSP
136: httpServletRequest.setAttribute(ChartServlet.IMAGE_MAP,
137: imageMap);
138:
139: //---set the Chart into the HttpSession so we can stream it in another request
140: httpServletRequest.getSession(true).setAttribute(
141: ChartServlet.CHART, axisChart);
142: } catch (ChartDataException chartDataException) {
143: chartDataException.printStackTrace();
144: } catch (PropertyException propertyException) {
145: propertyException.printStackTrace();
146: }
147:
148: this .getServletContext().getRequestDispatcher(
149: "/imageMapChart.jsp").forward(httpServletRequest,
150: httpServletResponse);
151: }
152:
153: }
|