ChartDirector 5.1 (.NET Edition)

BaseChart.makeSession


Usage

[VB] Public Function makeSession(sess As System.Web.SessionState.HttpSessionState, name As String [, imageFormat As Integer ]) As String
[C#] public string makeSession(System.Web.SessionState.HttpSessionState sess, string name [, int 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 IIS servers.

For PNG, GIF, JPG, BMP or WBMP chart images, you may use the WebChartViewer control instead. This is usually more convenient than makeSession.

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. Please refer to BaseChart.makeTmpFile if you would like to consider this method.

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.aspx" 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:

[VB]
Dim query1 As String = c.makeSession(Session, "chart1")

[C#]
string query1 = c.makeSession(Session, "chart1");

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

<IMG SRC="getchart.aspx?<%=query1%>">

If an ASP.NET web image control is used for image display, the following code can be used (assuming "imgControl" is the web image control):

[VB]
imgControl.ImageUrl = "getchart.aspx?" & c.makeSession(Session, "chart1")

[C#]
imgControl.ImageUrl = "getchart.aspx?" + c.makeSession(Session, "chart1");

Note that the above assumes "getchart.aspx" 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. Also, the directory that contains "getchart.aspx" must be in the same web application as your script, otherwise "getchart.aspx" will be unable to access the session variables created by your script.

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
sess(Mandatory)The session object of an IIS Active Server Page.
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.aspx".