Asp.net| Data | statistics | Graphics in the use of Excel processing reports, often to use the system with the chart tool to generate a scale diagram, not only intuitive, but also professional. Of course, the Office Web Components feature can also be used in WEB applications, but it is complex. Under the. NET Framework, simple programming makes it easy to make authentic scale diagrams. In the use of GDI + graphics, in addition to skilled application. NET provides, but also from the overall grasp of the graphics generated coordinates. In GDI +, the upper-left corner of the coordinates (0,0), the bottom right corner to do the maximum value.
In this section we will draw the graph by gid+. For example simulation, we use array data to simulate company business data.
Create a new Web form, named Gdi_sample2.aspx, with the following logical code:
'-----Code begin-----
Imports System.Drawing
Imports System.Drawing.Bitmap
Imports System.Drawing.Graphics
Imports System.Drawing.Imaging
Public Class Gdi_sample4
Inherits System.Web.UI.Page
#Region the code generated by the Web Forms Designer
' Omit the code generated by the form designer here
#End Region
' defines a public array variable that is used to store data from the simulated company sales
Public data (5, 1) as String
Private Sub Page_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
' The user code to place the initialization page here
Dim I as Int16
Dim Objbitmap as Bitmap
Objbitmap = New Bitmap (400, 300)
' Declare Graphics object
Dim Objgraphics as Graphics
' Specify the canvas
Objgraphics = Graphics.fromimage (Objbitmap)
' Set background color to white
Objgraphics.clear (Color.White)
' Draw a graphic border, pay attention to the space of the underline, for a pixel
Objgraphics.drawrectangle (Pens.black, 1, 1, 398, 298)
' Generate table Header text
Objgraphics.drawstring ("The first half of the company's turnover figures", New Font ("XXFarEastFont-Arial", FontStyle.Bold), Brushes.black, New PointF (60, 5))
' Get Analog data
GetData ()
Dim Monthcolor as PointF = New PointF (260, 40)
Dim fontinfor as PointF = New PointF (285, 36)
' Draw a schematic color legend
For i = 0 to 5
' Draw the fill rectangle.
Objgraphics.fillrectangle (New SolidBrush (GetColor (i)), Monthcolor. X, Monthcolor. Y, 20, 10)
' Draw a rectangular border.
Objgraphics.drawrectangle (Pens.black, Monthcolor. X, Monthcolor. Y, 20, 10)
' Draw the Legend Description text--data (i, 0)
Objgraphics.drawstring (data (i, 0), New Font ("XXFarEastFont-Arial,", Brushes.black, Fontinfor)
' Move the coordinate position and move only the Y-direction value.
Monthcolor. Y + 15
Fontinfor. Y + 15
Next I
' Iterate over each data source and draw a rectangular chart (that is, a column of columns) based on the size of the data.
For i = 0 to 5
' Draw the fill rectangle.
Objgraphics.fillrectangle (New SolidBrush (GetColor (i)), (I *) +, 270-cint (data (I, 1)), CInt (Data (I, 1))
' Draw a rectangular border line.
Objgraphics.drawrectangle (Pens.black, (i *) +, 270-cint (data (I, 1)), CInt (Data (I, 1))
Next
' Draw the schematic coordinates
Objgraphics.drawline (New Pen (Color.Blue, 1), 10, 0, 10, 320)
Objgraphics.drawline (New Pen (Color.Blue, 1), 10, 270, 200, 270)
' Add a numeric marker to the schematic coordinates and pay attention to the calculation of the coordinates.
For i = 0 to 5
Objgraphics.drawline (New Pen (Color.Blue, 1), I * +, I * 50 + 20)
Objgraphics.drawstring ((250-i * 50). ToString, New Font ("XXFarEastFont-Arial", Brushes.black, I * 50 + 8)
Next
' Statistic total sales
Dim Scount as Integer
For i = 0 to 5
Scount + + CInt (data (I, 1))
Next
' Define a pie angle variable
Dim SCG as Single = 0
Dim STG as Single = 0
For i = 0 to 5
' Calculate current angle value: Monthly Sales/Total sales * 360, get the angle size of the month in the pie chart.
SCG = CInt (Data (I, 1))/Scount * 360
[1] [2] Next page