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