A servlet handles an HTTP request for generation of charts by basically following
the steps outlined below:
The charts generated by JetChart are painted on the graphical context of the Graph,
ScatterGraph or PieGraph classes, found in the package com.jinsight.jetchart.
These classes descend from java.awt.Panel, which has to be laid out and displayed on a
valid container, like a java.awt.Frame object. However, servlets are Java applications typically running in
a headless server, where no display or graphical environment is available, therefore requiring the generation
of offscreen images using any of the following approaches:
Create an invisible container, on which the chart context is laid out. The
ChartEncoder class internally creates a Frame object, adding an instance
of Graph, ScatterGraph or PieGraph to it. Additionally, the ChartEncoder class is a wrapper around the
API of the image encoders and implements methods to trigger the encoding process. The
Frame object is also used to create the offscreen image using a java.awt.Image instance, to be
passed to an image encoder and outputed as a GIF, JPEG or PNG binary stream.
Create a java.awt.image.BufferedImage object and draw chart on it, directly using
one of the available image encoders to encode the BufferedImage object. The following
classes implement image encoders:
The BufferedImage class has a constructor and does not rely on a subclass of
java.awt.Component to be created, as the first approach describes. However, only JDK
1.2 and newer versions implement the BufferedImage class.
Create a java.awt.BufferedImage object and draw chart on it, using the Java Advanced Imaging(JAI) API to encode chart into a JPEG or PNG image.