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.
- Same as above, but instead of using HTTP query parameters to pass the data, use "session variables". This overcomes the limitations of HTTP query parameters and can be used for large amount of data.
- Perform the database query and create the chart image in the script for the HTML page. Save the chart image to a "session variable". The <IMG> tag script retrieves the chart image from the session variable and delivers it to the browser.
This approach is commonly used in 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 may not have write access to most directories.)
© 2009 Advanced Software Engineering Limited. All rights reserved.