Introduction
The Microsoft Chart Controls provide ASP.NET developers with an API and a Web control for creating and displaying charts in a web page. Behind the scenes, the Microsoft Chart Controls take the data to be plotted and dynamically generates an image. This image can be generated using one of three techniques: the Chart Web control can generate the image and save it to the web server's file system in a specified location; the Chart control can generate the image and store it in memory, session, or elsewhere, and have that image served by a built-in HTTP Handler, ChartHttpHandler; or the Chart control can send back the binary contents of the chart image directly to the browser. The chart image can be rendered using one of four image types: PNG, JPG, BMP, or EMF. And when rendering a JPG you can specify its compression level.
Regardless of the image file type and the technique used to generate the image, the Chart Web control renders an element whose src attribute references the image (or the image-producing HTTP Handler or ASP.NET page). When a browser requests a web page with a Chart control on it, it receives this element as part of the page's rendered markup and then makes a request to the URL specified in the src attribute (just like it does for any other image on a web page). The chart image file the browser requests either already exists in which case its contents are returned, or the image is dynamically-generated. Either way, the end result is that the browser is sent back the chart as an image file, which is displays.
This article explores the three different techniques the Microsoft Chart Controls has at its disposal for generating chart images. We'll look at how to use each option, enumerate the pros and cons, and discuss when to consider using one option over another. Read on to learn more!
Generating And Serving Static Images
The simplest and most straightforward manner for generating the chart images is to have the Chart Web control itself create and save the chart image to the web server's file system whenever a page is requested. In short, whenever a page with a Chart control is requested, the Chart control takes the data to be plotted and generates an image of the appropriate image type (PNG, JPG, etc.). It then saves this image in a specified folder and renders an element whose src attribute points to the just-created image.
The two key Chart control properties that dictate how the chart image is rendered are ImageStorageMode and ImageLocation. To have the chart images rendered as a static file on the web server's file system, set the ImageStorageMode property to UseImageLocation and the ImageLocation property to the file name and folder name where you want the images stored.
The following snippet shows how to create a Chart control that saves the generated chart image to a specific file on the file system, ~/Images/Chart.png. This location is specified via the ImageLocation property.
ImageLocation="~/Images/Chart"
ImageStorageMode="UseImageLocation"
ImageType="Png">
...
View Full Details...............................
No comments:
Post a Comment