ChartDirector 5.1 (PHP Edition)

BaseChart.makeSession


Usage

makeSession(name[, imageFormat])

Description

Generates the chart as an image and save it to a session variable.

The makeSession method is designed to support web applications in which the chart is generated in the script that outputs HTML.

This method requires session variables be enabled in the web server, which should be the default for PHP servers.

HTML cannot "contain" any image. It can only contain the URL of the images, typically in <IMG> tags. Other tags, such as <IFRAME>, <OBJECT> or <EMBED>, or the "background" property of CSS, etc, can also be used. The browser will use the URLs to load the images from separate HTTP connections.

In the followings, for conciseness, we will use <IMG> in the description. It should be noted that the description applies to other tags to load the chart image as well.

As HTML cannot contain any image, the script that outputs HTML cannot output the chart image. It needs to save the image in some place, and output an <IMG> tag with an URL for retrieving the saved image.

To save the chart image, a common method is to save it to the hard disk. The URL to load the image is then the URL of the image file.

However, as a web server can be accessed by multiple users concurrently, each chart needs a unique file name, otherwise they may overwrite each others. This causes files to build up on the hard disk, and additional code is needed to periodically clean up old chart image files on the hard disk.

The makeSession method saves images in session variables, avoiding creating image files on the hard disk. The makeSession method returns a URL query string, which can be used with a ChartDirector utility script "getchart.php" to load the image from session variables.

To avoid having to save the chart image at all, an alternative approach is to use the URL of a script in the <IMG>. The browser will then access the script to load the image. The script can generate the chart image and streamed directly to the browser.

Note that the chart is not generated by the script that outputs HTML, but by another script that handles the <IMG> tag.

A limitation of this method is that the charts cannot contain image maps. Image maps are HTML tags (<MAP> and <AREA> tags) and can only be outputted by the script that generates HTML. If image maps are used, the charts need to be generated in the script that outputs HTML.

In a typical application, the chart is created like:

$query1 = $c->makeSession("chart1")

The web page then includes an <IMG> tag as follows:

<IMG SRC="getchart.php?<?php echo $query1 ?>">

Note that the above assumes "getchart.php" is in the same directory as your script. If it is in a different directory, you would need to modify the path in the <IMG> tag.

Note: To output true vector graphics in SVG or SVGZ format, please ensure BaseChart.enableVectorOutput is called immediately after creating the BaseChart object. Otherwise the output will be a bitmap image embedded in SVG or SVGZ.

Arguments

ArgumentDefaultDescription
name(Mandatory)The name of the session variable used to store the chart image. If there are multiple chart images in the same web page, each image must use a different name.
imageFormatPNGA constant representing the format of the image. Must be one of the predefined constants PNG, JPG, GIF, BMP, WMP, SVG or SVGZ.

Return Value

A string representing the query parameters for retrieving the image using "getchart.php".