public String makeSession(HttpServletRequest request, string name [, int imageFormat ])
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 JSP 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. 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.jsp" 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:
String chart1URL = c.makeSession(request, "chart1");
The web page then includes an <IMG> tag as follows:
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'>
Note that the above assumes "getchart.jsp" 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.jsp" must be in the same web application (servlet context) as your script, otherwise "getchart.jsp" will be unable to access the session variables created by your script.
As an alternative to getimage.jsp, ChartDirector also has a
GetSessionImage servlet that performs the same function. This is useful for servlet applications that do not use JSP.
For example, if you have mapped "*.chart" to GetSessionImage, you may use "getchart.chart" as the URL instead of "getchart.jsp". Please refer to the
Installation section for details.
Note: The getimage.jsp may not work properly in some very old web servers. In this case, the getimage.jsp will automatically redirect itself to the GetSessionImage servlet. Therefore, it may be useful to install the GetSessionImage servlet even if you may not need it.
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.
A string representing the query parameters for retrieving the image using "getchart.jsp" or the
GetSessionImage servlet.
© 2012 Advanced Software Engineering Limited. All rights reserved.