ChartDirector Ver 4.1 (PHP Edition 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. Same as above, but instead of using HTTP query parameters to pass the data, use "session variables".

    One limitation of HTTP query parameters is the query cannot exceed 2048 bytes, so it cannot pass too much data. "Session variables" can be used in this case to transfer data among scripts.

  4. Perform the database query and create the chart image in the script for the containing HTML page. Save the chart image to a "session variable". Use an <IMG> tag inform the browser to pick up the image from the "session variable".

    This approach is commonly used in creating clickable charts, but it can be used for other charts as well. ChartDirector has a special method BaseChart.makeSession to support this approach.

    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.)