graph demo

Graph Documentation - Implementing Graphing Servlets

graph demo[ Home ] [ Products ] [ Downloads ] [ Purchase ]
[ Support ] [ About Us ]

Implementing Graphing Servlets

Overview
Each graph style is available as a Java Servlet. The ./ServletFiles/ directory of the downloaded package contains the class files for each graph style.

(Download the package here)

The Servlet Graphs operate on the Web Server within a Servlet Engine (eg. Tomcat, WebSphere, WebLogic, JRun etc). A graph is added to a page via the standard HTML IMG tag where SRC element is set to the URL of the graphing servlets. When the page is viewed the browser will send the request for the graph to the web server which, in turn, will pass the request to the Servlet Engine and the graphing servlet. The graphing servlet will then dynamically construct the graph image which is then returned back to the browser where it is displayed to the user.

Web Server Requirements
The web server will need to have a Servlet Engine set-up and installed in order to operate the graphing servlets (eg. Tomcat, WebSphere, WebLogic, JRun etc).

There are no special requirements on the client browser

Set Up and Implementing Procedure
A graph servlet can be added to a web page with the following steps:-

Step 1 - Install the Graphing Servlets in the Servlet Engine

This procedure may vary slightly between different Servlet Engines and as such you may also need to refer to your Servlet Engine's documentation.

With most modern Servlet Engines the Graphing Servlet class files will need to be installed as a web application. The graphing servlets have been built within the package jpowered.graphs which can be found in the ./ServletFiles/ directory.

The following describes how the JPowered Graphing package would be added to Tomcat 5.5.

a) Under the ./webapps/ directory of the Tomcat installation create this directory structure:-

./webapps/jpowered/WEB-INF/classes/

b) From the ./ServletFiles/ directory of the downloaded package copy the ./jpowered/ directory and all it's contents to the ./webapps/jpowered/WEB-INF/classes/ created in the previous step.

c) From the ./ServletFiles/ directory of the downloaded package copy the web.xml file and place this in the ./webapps/jpowered/WEB-INF/ directory of Tomcat.

d) Restart Tomcat

Step 2 - Set up the Configuration data

The graphing servlets provide the following two options for inputting the configuration data.
a) with a Configuration File.

The servlet will read all the configuration parameters from a specified file. To use this option incorporate the URL of the configuration file into the IMG tag (see Step 4).

Click on the following to view an example property file for each chart style:-

lineproperties.txt
areaproperties.txt
pieproperties.txt
vbarproperties.txt
svbarproperties.txt
hbarproperties.txt
shbarproperties.txt

As you will see from the example file each property is specified on a name, value basis. Adjust the property values to specify the characteristics of the graph and then place this file in the same directory as your web page.

A full description of each property can be found in the appropriate parameter reference:-
Line Graph Parameters
Area Graph Parameters
Pie Chart Parameters
Vertical Bar Graph Parameters
Stacked Vertical Bar Graph Parameters
Horizontal Bar Graph Parameters
Stacked Horizontal Bar Graph Parameters

b) Server Side process

This option allows the graph servlets to obtain all the configuration data from another server side application. The server side script should be designed to output the configuration data in the same format as the file in option a) above.

For example scripts see the ./ServerTemplateScripts/ directory of the downloaded package.

For a more in depth look at this process also see the Tutorials

With most implementations supplying the configuration data either from a data file will be the most efficient, however supplying this data via a server side script is useful where the graph properties need to be dynamically calculated. eg. dynamic axis labelling.

Step 3 - Set up the Graph data

As with the configuration data there are two options for supplying the data values to the servlet
a) with a Data File.

The servlet will read all the data from a specified file. To use this option incorporate the URL of the data file into the IMG tag (see Step 4). Click on the following to view an example data file:-
datafile.txt

As you will see from the example file each piece of data is specified on a name, value basis. The first element of each line represents the data name (specifying the series and data order) and then the value.

For more information on the data format see Supplying the Graph with Data
b) Server Side process

This option is the most powerful and gives the servlet the ability to retrieve data from databases. This method involves specifying a server side script in the IMG tag of the html page (see Step 4) which in turn returns the data to the graph servlet. This provides enormous flexibility for data acquisition. The server side script can be constructed in the language of your choice (eg. PHP, JSP, ASP etc) and as such can be written to acquire data from the widest variety of sources, multiple databases etc.

To instruct the servlet to retrieve data from a server side script simply add the URL of your server side script into the IMG tag of the HTML page (see Step 4). The server side script should be designed to output the data in the same format as the file in option a) above.

For example scripts see the ./ServerTemplateScripts/ directory of the downloaded package.

For a more in depth look at this process also see the Tutorials

Step 4 - Incorporate the Servlet IMG tag into the HTML page

The final step is to incorporate the graph into the HTML page. This is done via the standard html IMG tag.

<img src="[ServletEngineURL]/jpowered/servlet/jpowered.graphs.[GRAPHSERVLETNAME]?
config=[URLconfigFile]&
data=[URLdataFile]"
width="500" height="420">

Where,

[GRAPHSERVLETNAME] - should be replaced with one of the following:-
  • LineGraphServlet
  • AreaGraphServlet
  • PiechartServlet
  • SVbarchartServlet
  • VbarchartServlet
  • HbarchartServlet
  • SHbarchartServlet
[ServletEngineURL] - should be replaced with the URL of the servlet engine. This can vary depending upon the servlet engine's configuration. For example with the standard install of Tomcat this may be:-
http://localhost:8080/jpowered/servlet/
( the port number may also vary )

[URLconfigFile] - should be replaced with the URL to either a Configuration file or server side process.

[URLdataFile] - should be replaced with he URL to either a Data file or server side process.

For example, to produce a line graph with the following,

Servlet Engine URL = http://www.yourdomain.com/
Configuration File URL = http://www.yourdomain.com/config.txt
Data Servlet = dataservlet.class

producing a graph image of 400 pixels by 300 pixels, the following IMG tag would be incorporated into the html page,

<img src="http://www.yourdomain.com/jpowered/servlet/jpowered.graphs.LineGraphServlet?
config=http://www.yourdomain.com/config.txt&
data=http://www.yourdomain.com/servlet/dataservlet" width="400" height="300">


Custom Solutions
If would like us to perform the set-up process, create custom built data scripts or help with any other part of your web application then we are pleased to offer you the following services:-
Set-Up, Installation and Configuration Service
Web Site Components Development Service
Web Application Development Service
Custom Software Development
JavaScript CSS Image Gallery