Using Aspimage to make graphics (i.)

Source: Internet
Author: User
Tags definition textout variable
For a long time did not bring a new article, the recent tofu busy company's business, neglect of my friends, here to everyone to say first
Sorry, there is no way, tofu also want to live AH.
Aspimage is a very good component of the Serverobjects site, which enables us to implement many of the graphics processing capabilities using ASP.
For example, tofu in the recent project needs to be the cost of statistics, to draw a column chart, pie, and so on, all need to use this component.
This component itself does not have built-in column graph function, we need to do this function, or the old rules, let's look at the code first.
Function Drawpillar (Arrnum)
The function of this function is to generate a column graph
' ************** The following is the variable definition ********************
Dim Arrcolor (13)
Dim arrNum1 ()
Dim i
Dim IntX
Dim inty
'--------------The following is the beginning of the code--------------------
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
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

Intmax=getmaxy (Arrnum)

Set Image = Server.CreateObject ("Aspimage.image")
image.maxx=620
image.maxy=300

intratio= (image.maxy-40)/intmax

Image.gradienttwoway RGB (41,137,204), Vbwhite, 0,1


' Image.backgroundcolor =vbblue
' Image.framerect 15,15,image.maxx-15,image.maxy-15

' Y axis
Image.x =40+2
Image.y =15
Image.lineto 40+2,image.maxy-20
Image.textout "↑", 40-5,14,false
Image.textout "unit: Yuan", 15,0,false
For I=1 to 10
Image.textout "-", ((image.maxy-40)/10) *i,false
' Image.textout CDBL ((INTMAX/10)) * (i), 0, ((image.maxy-40)/10) * (11-i), False
Next

' X axis
Image.x =image.maxx-15
Image.y =image.maxy-20
Image.lineto 40,image.maxy-20

Image.textout ">", Image.maxx-15-4, Image.maxy-20-9,false
For I=1 to 12
Image.textout I & "Month", 40+ I * (30+15) -20, Image.maxy-20,false
Next

If Intmax=0 Then
Intmax=1
End If

' There are 12 months in a year, producing 12 colors.
Intx=40

For I=0 to 11
Image.backgroundcolor = Arrcolor (i)
Image.rectangle intx+20,image.maxy-20, intx+50, Image.maxy-20-arrnum (i) *intratio
Image.textout Arrnum (i), intx+20, Image.maxy-32-arrnum (i) *intratio, False
intx=intx+ 30 +15
Next
Image.filename=server. MapPath ("Http://edu.cnzz.cn/NewsInfo/test.jpg")
Image.saveimage

Set image=nothing
Response.Write "End Function

function Getmaxy (arrnum)
' The function of this function is to get the largest number in the array
' *************** The following is the variable definition ************
Dim i
Dim Intmax ' Registers
'---------------The following is the beginning of the code------------
Intmax=0
For i=0 to UBOUND (arrnum)
If CDBL (Intmax) < CDBL (Arrnum (i)) then
Intmax=arrnum (i)
End If
Next

Getmaxy=intmax
End Function

We get a Aspimage instance through code set Image = Server.CreateObject ("Aspimage.image") and now
We can use Aspimage to provide us with the moving features.
image.maxx=620
image.maxy=300
We can set the area of the graph we need to draw.
Image.gradienttwoway RGB (41,137,204), Vbwhite, 0,1
This is a very, very good way and we can add a progressive fill to the back of the picture.

' Y axis
Image.x =40+2
Image.y =15
Image.lineto 40+2,image.maxy-20
Image.textout "↑", 40-5,14,false
Image.textout "unit: Yuan", 15,0,false
For I=1 to 10
Image.textout "-", ((image.maxy-40)/10) *i,false
Next

This code is a Y-axis code, do not underestimate this "↑", Tofu took a long time to finish. :)
' X axis
Image.x =image.maxx-15
Image.y =image.maxy-20
Image.lineto 40,image.maxy-20

Image.textout ">", Image.maxx-15-4, Image.maxy-20-9,false
The x axis is relatively simple.

' There are 12 months in a year, producing 12 colors.
Intx=40

For I=0 to 11
Image.backgroundcolor = Arrcolor (i)
Image.rectangle intx+20,image.maxy-20, intx+50, Image.maxy-20-arrnum (i) *intratio
Image.textout Arrnum (i), intx+20, Image.maxy-32-arrnum (i) *intratio, False
intx=intx+ 30 +15
Next
This end code is the final code to generate the column, I do not explain the specific.
Turn from: Dynamic Network production guide www.knowsky.com

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.