ASP.NET implementation data chart

xiaoxiao2021-03-06  112

Author: Ma Jinhu from: yesky

Insert a chart in the ASP, the common method is to use the MSChart control. So is the ASP.NET is also the case? The answer is not possible. We know that ASP.NET is a compile language. When the client calls the ASP.NET page, it is actually a complicated compiler, compiling production of MSIL files, stored locally, MSIL files actually It is an intermediate language file, then this file is compiled again through the Just In Time compiler, so that the ASP.NET page you call is displayed. For different machines, there are different JIT It is also compiled into a different machine language, which is Microsoft to vigorously advocate the so-called cross-platform principle of ASP.NET. When the ASP.NET page is compiled into a msil file, the class library used by the compilation must be a managed code, and the ActiveX control is filed in the machine language, he belongs to the tube code file. Unmanaged code. So it is impossible to call the MSChart component directly in ASP.NET. Although you can use the .NET framework to convert this MSChart component into a managed code file, this process is relatively complicated, and the chart speed generated by this method is quite slow, and it is limited by the MSChart component. For complex charts, it is unable to use him to generate. This article will take advantage of how to implement charts in ASP.NET as an example. In fact, what we see is not a chart, but a picture. Generate a picture on the server side, then draw a variety of information you want to display to the user on the image, then send a picture to the client through the browser, thereby forming a chart, which is a method to explore this article. Although this approach is more complicated, the operation is flexible, very practical, especially for charts on the Internet, and will introduce specific implementation methods. One. The program design and operational environment described herein (1). Microsoft Window 2000 Server Edition (2) .. Net Framework SDK Beta 2 or above. In the ASP.NET, you can implement the key steps of the data chart and the solution: Draw a chart in the ASP.NET page, there are two steps, which one, create a picture object (Bitmap). Then use the method provided by the .NET Framework SDK, draw the graphics you want on this picture, such as drawing lines, draw points, etc. Second, in order to make it more suitable for transmission, this picture object is saved in "JPEG" format and is displayed. Let's take a look at the specific implementation of these two steps. (1). Let's take a look at how to create a dynamic picture on the ASP.NET page and display it. Creating a picture object is actually very easy, using the "Bitmap" class in the namespace "system.drawing", the following statements can create a bitmap object:

// Create a "Bitmap" object bitmap image = new bitmap (400, 400);

Modify the two parameters of the "BitMap" to change the length and wide width of the created bitmap object. The bitmap object that has been created can be displayed by the Save method of the Bitmap class. Since the bitmap files take up a lot of space, in order to facilitate network transmission, it is generally converted to "JPEG" or "GIF" files. The following statement is to convert the bitmap object that has been created into "JPEG" file: // Save this object in "JPEG" format, displayed in the client. Save (response. OutputStream, Imageformat. JPEG);

Slightly modified, you can display the bitmap object in the "GIF" file, as follows:

// Save this object in "JPEG", displayed in the client. Save (response. OutputStream, Imageformat. GIF);

The role of chart3.aspx is ASP.NET dynamically creates a picture and displayed:

<% @ Page language = "c #" ContentTy = "image / jpeg"%> <% @ Import namespace = "system"%> <% @ Import namespace = "system.drawing"%> <% @ import namespace = "system .Drawing.drawing2d "%> <% @ import namespace =" system.drawing.imaging "%>