To display any image in a HTML web page, an <IMG> tag is needed. The browser will first load the HTML web page. When it sees <IMG> tag, it will load the image using the URL in the <IMG> tag. If the image happens to be a chart, the <IMG> tag URL may point to a charting script that uses ChartDirector to generate the chart on the fly.
Thus two scripts may 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 <IMG> tag URL that delivers the chart image to the browser.
To create a chart in which the data come from a database, there are several options:
- Perform the database query in the <IMG> tag script to obtain the data, create the chart image, and deliver the chart to the browser.
- Perform the database query in the script for the HTML page, then pass the data to the <IMG> tag script as HTTP query parameters. The <IMG> tag script retrieves the data from the HTTP query parameters, create the chart image, and deliver the chart to the browser.
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).
One limitation of this method is that most browsers have a limit of around 2048 bytes for query parameters. So it may not be suitable for large amounts of data.
- Perform the database query and create the chart image in the 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 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 using temporary files 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 may not have write access to most directories.)
© 2017 Advanced Software Engineering Limited. All rights reserved.