bar graph

2D / 3D Horizontal Bar Graph Documentation

[ Bar Graph Home ] [ Tutorials ] [ Getting Started ] [ Examples & Demos ] [ Solutions ]

Implementing the Servlet (server side solution)

Incorporating the bar graph servlet into your web page involves the following steps,

    1. Load the Servlet Class files into your Servlet Engine
    2. Set up the Configuration data
    3. Set up the Bar Graph data
    4. Incorporate the Servlet IMG tag into your HTML page

Step 1 - Load the Servlet Class files into your Servlet Engine
In order to use the Bar Graph servlet you will need to have a servlet engine already setup and configured on your web server. There are a wide variety of servlet engines available and therefore specific details for each engine are beyond the scope of this documentation. We will limit this discussion to the following two engines,

Tomcat - for full details see http://jakarta.apache.org/tomcat/

Servletrunner ( runs on the local machine as part of the JSDK environment )
see http://java.sun.com/products/servlet/

For a full list of available Servlet Engines and further information please -
click here

The first step is to place the following class files and the 'encoder' directory in your Servlet Engines class file directory.
For Tomcat this is usually /WEB-INF/classes/ and for the default setup of the JSDK environment this is the /examples/ directory.

hbarcharts.class
HbarchartServlet.class
encoder

(these classes & directory can be found in the Servlet directory ).

Notes :

  • The servlet utilizes an Image encoder in order to produce the graph image.
  • It is also vital that a graphics environment exists on your server, for Microsoft Windows based servers this is always the case however for UNIX and Linux it is important that the X11 environment is in operation. If for whatever reason a graphics environment is not present on your server then you may wish to consider the PJA ( Pure Java AWT ) alternative - for full details on this click here.

^back to top

 

Step 2 - Set up the Configuration data.
The Bar Graph servlet provides the following two options for inputting the configuration data.

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 the IMG tag (see Step 4).

The "../../../bar_graph/hbargraph/Documentation/barprops.txt" file contained in this directory is an example file containing the configuration data ( click here to view the example file ). 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 bar graph and then place this file in the same directory as your web page.

For a full description of each property please see
"Configuration Options and Parameters".

b) Server Side process
This option allows the bar graph servlet to obtain all the configuration data from a 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.

As with the previous option the URL of the server side process is specified in the <IMG> tag of your HTML page (see Step 4).

For an example script see BarConfigServlet.java in the ServerTemplateScripts directory.

For most implementations supplying the configuration data from a data file will be the most efficient, however supplying this data via a server side script is useful where you wish to hold this data in a database. A server side script would then be used to read the config data from the database and then supply to the servlet at runtime.

^back to top

Step 3 - Set up the Bar Graph data
As with the configuration data there are three options for supplying the data values to the servlet,

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 the IMG tag (see Step 4).

The "../../../bar_graph/hbargraph/Documentation/bardata.txt" file contained in this directory is an example file containing the data ( click here to view the example file ). As you will see from the example file each piece of data is specified on a name, value basis.

Simply create a similar file adding your data in the values. For a full explanation of this file please see the "Retrieving Data from Files" under the "Data and Configuration" section ( or click here).

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, giving enormous flexibility for data acquisition. The server side script can be constructed in the language of your choice 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 an example script see BarDataServlet.java in the ServerTemplateScripts directory.

For a full description of constructing a server side script which retrieves data from a database see the section "Connecting the Graph to a database" under the "Data and Configuration" section ( or click here).

^back to top

Step 4 - Incorporate the Servlet IMG tag into your HTML page.
The final step is to incorporate the graph into your HTML page. This is done via the standard html <IMG> tag.

<img src="[ServletEngineURL]/HbarchartServlet?
config=[URLconfigFile]&
data=[URLdataFile]"
width="500" height="420">

Where,

[ServletEngineURL] should be replaced with the URL for your servlet engine. If running ServletRunner on your local machine this would be, http://localhost:8080/servlet/

[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 if we have the following,

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

producing a graph image of 400 pixels by 300 pixels, we would incorporate the following <IMG> tag into our html page,

eg.

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

^back to top

 

If you experience any difficulties implementing then please do not hesitate to contact us at,
JPowered Support

« back to Documentation Index

« back to Getting Started

[ Bar Graph Home ] [ Tutorials ] [ Getting Started ] [ Examples & Demos ] [ Solutions ]

Getting Started

Documentation

Examples

Tutorials

Common Problems
This section describes and provides solutions to common problems.