com.objectplanet.chart
Class ChartServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--com.objectplanet.chart.ChartServlet
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public class ChartServlet
- extends javax.servlet.GenericServlet
This servlet takes a chart applet tag as input and
generates the applet as an image.
In the standard version the image returned to the client is jpeg
encoded. You can use another encoder by creating a class that extends
the ChartServlet class and overrides encodeChartImage() method.
If you want to use the GifEncoder from ACME, do the following:
- Download the ACME GifEncoder
- Add the ACME packages to your CLASSPATH or java runtime environment
- Extend the ChartServlet class and override the encodeChartImage method
import com.objectplanet.chart.*;
import java.io.*;
import java.awt.*;
import javax.servlet.*;
import Acme.JPM.Encoders.*;
public class GifChartServlet extends ChartServlet {
public void encodeChartImage(Image image, OutputStream out, ServletResponse res) throws IOException {
// set the response type to a gif image
res.setContentType("image/gif");
// create a gif image and send it to the client
GifEncoder encoder = new GifEncoder(image, out);
encoder.encode();
out.flush();
}
}
You find the class above here.
- Compile and make sure the class is available to your java runtime
- Call the servlet: <img src="http://localhost:8080/servlet/GifChartServlet?sampleValues=10,20,30,40,50">
- Author:
- Bjorn J. Kvande.
See Also:Serialized Form
Field Summary |
protected java.util.Hashtable |
chartApplets
The chart applets used to render the chart. |
Method Summary |
protected void |
encodeChartImage(java.awt.Image image,
java.io.OutputStream out,
javax.servlet.ServletResponse res)
Encodes the specified java image to a jpeg bytestream. |
void |
init(javax.servlet.ServletConfig config)
This method is called when the servlet is placed into service.
|
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res)
The service. |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
chartApplets
protected java.util.Hashtable chartApplets
- The chart applets used to render the chart. Each chart is
keyed by the name, with default being bar, line, and pie.
ChartServlet
public ChartServlet()
encodeChartImage
protected void encodeChartImage(java.awt.Image image,
java.io.OutputStream out,
javax.servlet.ServletResponse res)
throws java.io.IOException
- Encodes the specified java image to a jpeg bytestream. Make a
subclass and override this method to support other image formats.
The content type has to be set before the image is written to
the output stream; res.setContentType("image/jpeg").
- Parameters:
image
- The image to encode.out
- The output stream to encode it to.res
- The servlet response.
java.io.IOException
init
public void init(javax.servlet.ServletConfig config)
- This method is called when the servlet is placed into service.
It creates the bar/line/pie charts to be used for generating
the chart images.
- Specified by:
init
in interface javax.servlet.Servlet
- Overrides:
init
in class javax.servlet.GenericServlet
service
public void service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res)
throws javax.servlet.ServletException,
java.io.IOException
- The service.
- Specified by:
service
in interface javax.servlet.Servlet
- Specified by:
service
in class javax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
- If the call could not be processed.
java.io.IOException