Thanks to the clear interfaces, it is very easy to create servlets providing chart images (or tables). In your servlet's doGet() or doPost() method:
ChartXMLDocumentHandler XMLDocHandler =
new ChartXMLDocumentHandler(contextURL, reader);
Chart chart = XMLDocHandler.createChart();
response.setContentType(chart.getContentType()); chart.putContent(response.getOutputStream());
The steps to get your Chart servlet up and running are listed below. If you are unfamiliar with servlet technology, you may find Java Servlet Pages helpful. However, with these instructions and using the Davisor Chart web application (inside the Davisor Chart demo download package) as an example, you should be able to create an own Chart servlet.
<servlet>
<servlet-name>xmlServlet</servlet-name>
<display-name>XML example servlet</display-name>
<servlet-class>XMLServlet</servlet-class>
</servlet>
This maps the servlet class to some servlet name. Note that servlet
definitions must be placed after context parameter, filter, and
listener elements in "web.xml". Consult your web server
documentation for the details of web.xml deployment description file,
or modify the "web.xml" inside the "chart.war" for
your needs.
<servlet-mapping>
<servlet-name>xmlServlet</servlet-name>
<url-pattern>/xmlServlet</url-pattern>
</servlet-mapping>
This maps a url to the named servlet. Servlet mappings lie in
"web.xml" after servlet definitions and before session
config and MIME mappings.jar cf mychart.war WEB-INF index.html examplesThe content of index.html is in the most simplistic form:
<html><body> <a href="xmlServlet?i=0">Example 1</a><br /> <a href="xmlServlet?i=1">Example 2</a> </body></html>
See the whole Java code for the servlet used to produce the examples below.
|
| A bar chart created by a servlet from XML. |
|
| Pie chart and legend, created by a servlet from XML and CSV. |