ChartDirector 6.2 (.NET Edition)

ASP.NET Output Methods with Viewers


Output as WebImage Objects

In the ASP.NET sample code included in ChartDirector, the chart is output as a WebImage object, then assigned to a WebChartViewer (for ASP.NET Web Forms) or RazorChartViewer (for ASP.NET MVC). The code is like:

[VB]
myViewer.Image = c.makeWebImage(Chart.PNG)
[C#]
myViewer.Image = c.makeWebImage(Chart.PNG);

In the above code, myViewer can be a WebChartViewer or RazorChartViewer. Internally, what the viewer does is as follows:

  1. Stores the chart image into a session variable.

  2. Generates an <IMG> tag with a special URL to load the image from the session variable.

  3. When the browser receives the HTML, it will follow the URL in the <IMG> tag to loads the image using a separate HTTP connection.
Note that the browser will use separate HTTP connections to load images. That is why the chart image needs to be stored in a session variable, as it persists across HTTP connections. For this to work, the web server must not have session variables disabled.

Output as Temporary Files

The WebChartViewer and RazorChartViewer also supports using files as the storage. This is useful for ASP.NET systems with session variables disabled or with unreliable session variables. ChartDirector has a special method BaseChart.makeTmpFile to create chart images as temporary files and automatically remove old temporary files. The code is like:

[VB]
myViewer.ImageUrl = "/tmp_chart/" & c.makeTmpFile(Server.MapPath("/tmp_chart"))
[C#]
myViewer.ImageUrl = "/tmp_chart/" + c.makeTmpFile(Server.MapPath("/tmp_chart"));

In the above code, the web application directory "/tmp_chart" is used to store the temporary files. Since BaseChart.makeTmpFile expects a file system path, Server.MapPath is used to map the web application path to a file system path.

For the above to work, the "/tmp_chart" directory must exist and the web server must have write access to the directory. In many systems, the web server runs under a limited privilege account representing the anonymous user, and may not have write access to the web application directory or its subdirectories. You may need to grant the web server account read, write and delete access to the "/tmp_chart" directory. If you are not sure which account the web server is using, you may consider to grant these rights to the "Everyone" group for testing purpose.