ChartDirector Ver 4.1 (Perl Edition)

Using ChartDirector with Database in Web Pages


To display any image in a HTML web page, one needs to insert an <IMG> tag in the HTML web page. When the browser sees the <IMG> tag, it will load the image using the URL in the <IMG> tag in another HTTP connection.

This is no difference to display a ChartDirector chart in a HTML web page. An <IMG> tag must be used. In this case, the URL in the <IMG> tag points to a "ChartDirector script" (a script using ChartDirector to create and deliver chart images) instead of a static image file.

Thus two scripts can be invoked when displaying a ChartDirector chart in a HTML web page - the script that create the HTML web page, and the script referenced in the URL of <IMG> tag that delivers the chart to the browser.

Strategies in Passing Data to ChartDirector

To create a chart in which the data come from a database, there are several options:

  1. Perform the database query in the ChartDirector script (the script referenced in the <IMG> tag) to obtain the data and create the chart.

  2. Perform the database query in script for the containing HTML page, and pass the data to the ChartDirector script as HTTP query parameters.

    This method allows the data from the database query to be used in multiple charts in the HTML page, and in the HTML page itself (eg. displayed as tables).

  3. Perform the database query and create the chart image in the containing HTML page. Save the chart image in a temporary file. Use an <IMG> tag to load the chart back from the temporary file.

    In some applications, the chart must be created in the containing HTML page (e.g. when creating clickable charts). However, the chart image can only be delivered through an <IMG> tag. So the chart image needs to be saved in a temporary location.

    To make this easy, ChartDirector has a special method BaseChart.makeTmpFile that saves charts in temporary files and automatically remove old temporary files.

    As an alternative to using temporary files, one method is to use "session variables". However, this requires the web server to support "session variables" and make the variables available to Perl. So this alternative will not be discussed in further details here.

    Note: When using temporary files, make sure the security settings allow the web server anonymous user to write to the temporary directory. (By default anonymous users cannot write to any directory.)