Using Aspimage to make graphics (II.)

Source: Internet
Author: User
Tags definition textout variable
We talked about how to use Aspimage to make column chart, the column chart is good to do, at least have the function of rectangular, we can come
Borrow, but if yes, what about pie charts?
Some friends did not say that the aspimage is not the function of pie? Yes, it is, but it's too hard to use.
Tofu has no way, after colleagues help, using our high school Learning Triangle formula (triangle formula?) Did you get it wrong? )
The function is finally made, and it is very convenient to use. Look, everybody.
Function Drawpie (Arrnum,arrtext)
' function function: they are arrays based on the specified values and display
' ********** The following is the variable definition **************************
Dim inttotal ' Current
Dim i
Dim intsettledangle
Dim Arrcolor (6)
'----------The following is the beginning of the code--------------------------
' Set color
I=0
Arrcolor (i) =rgb (255,255,255)
I=i+1
Arrcolor (i) =rgb (255,255,0)
I=i+1
Arrcolor (i) =rgb (255,0,255)
I=i+1
Arrcolor (i) =rgb (0,255,255)
I=i+1
Arrcolor (i) =rgb (255,0,0)
I=i+1
Arrcolor (i) =rgb (0,255,0)
I=i+1
Arrcolor (i) =rgb (0,0,255)
I=i+1
' The following starts processing the data
' Get the total number of numbers first

Inttotal=0
For i=0 to UBOUND (arrnum)
Inttotal=inttotal + arrnum (i)
Next

Set Image = Server.CreateObject ("Aspimage.image")

' Set the area size of the image
image.maxx=300
image.maxy=300
' Generate progressive color
Image.gradienttwoway RGB (41,137,204), Vbwhite, 0,1

' Processing angle
Intsettledangle=0
Intrectstart=0
For i=0 to UBound (arrnum)
Intangle= (Arrnum (i)/inttotal) *360
' One of the drawing sectors, which eventually synthesizes a complete circle
Set Image=drawsinglepie (Image, 360-intsettledangle,arrcolor (i))

' Describe the image content at the bottom of the image
Image.backgroundcolor =arrcolor (i)
Image.rectangle intrectstart+10* (i+1), 250,intrectstart+10* (i+1) +10,260
Image.textout Arrtext (i), intrectstart+10* (i+1) +10,245,false

' Describe the image content at the bottom of the image
Image.backgroundcolor =arrcolor (i)
Image.rectangle intrectstart+10* (i+1), 270,intrectstart+10* (i+1) +10,280
Image.textout CStr (intangle) & "%", intrectstart+10* (i+1) +10, 265,false
Intrectstart=intrectstart+50
Intsettledangle=intsettledangle + Intangle
Next
Image.filename=server. MapPath ("Http://edu.cnzz.cn/NewsInfo/test.jpg")
Image.saveimage
Set image=nothing
Response.Write "End Function

function Drawsinglepie (Image,intangle,intcolor)
' function function: Draw a rectangle based on the specified angle and color
' ************** The following is the variable definition ********************
Const pi=3.1415926 ' pi
Dim Pii ' After 180-angle converted circumference, radians
Dim x1,x2,x3,x4 ' 4 x coordinates
Dim Y1,y2,y3,y4 ' 4 Y-coordinate
Dim IntR ' Circle radius, this radius is not the true radius of the circle, but can be used to fix the position of the center
'--------------The following is the beginning of the code--------------------
'**********************************
'*
' * (x1,y1), (x2,y2) and center must be on a straight line through (0,0) Bevel 45
'***********************************
pii=pi/180
If Intangle > 360 Then
intangle=intangle-360
End If
x1=10
y2=10
x2=250
y2=250

Intr= (X1+X2)/2
'************************************
'*
' * Following the use of the triangle formula to get the corresponding point coordinates
'************************************
If intangle<135 Then
' Less than 135 angles
Angle=intangle*pii
X3=tan (ANGLE-45*PII) *intr+intr '
Y3=0
X4=0
Y4=0
ElseIf intangle=135 Then
x3= (IntR) *2
Y3=intr
X4=0
Y4=0
ElseIf intangle<315 Then
Angle=intangle*pii
Inttemp= (Intr/tan (ANGLE-135*PII))-intr
X3=250+inttemp
y3=250
X4=0
Y4=0
ElseIf intangle=315 Then
x3= (-INTR) *2
Y3=intr
X4=0
Y4=0
Else
Angle=intangle*pii
X3=tan (ANGLE-45*PII) *intr+intr
Y3=0
X4=0
Y4=0
End If

Image.backgroundcolor =intcolor
Image.pie X1,y1,x2,y2,x3,y3,x4,y4

' Image.textout 360-intangle, (125+x3)/2+20, (125+y3)/2+20,false
' Image.textout Intratio, Intposx,intposy,false

Set Drawsinglepie=image
End Function

Finally, we can use the Drawpie to pass the array of data to be displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.