⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yearpowergraph.asp

📁 ASPTest 网络基础网页设计
💻 ASP
字号:
<% 
'**********以下数据由绘图程序动态确定***********************
   
'横纵坐标点数
Const xNum = 12
Const yNum = 10 
   
'横纵坐标间距
Const xWidth = 50
Const yWidth = 20
 
'横,纵坐标单位
Const xUnit = "月"
Const yUnit = "KW"

'横坐标最大值最小值
Const xMin = 1
Const xMax = 12
  
'坐标周围所留空白用以显示字符串
Const xLeft = 60
Const xRight = 60
Const yTop = 40
Const yButtom = 40
   
'定义三个坐标数组
Dim yArray1(48),yArray2(48),yArray3(48)

'定义用于显示的标题
Dim strTitle

'定义用于显示曲线标题的字符串
Dim strDate1,strDate2,strDate3

'定义纵坐标最大最小值   
Dim yMax,yMin

'定义纵轴刻度单位
Dim yIncrement

'定义一些临时变量以供使用
Dim i,j,strTemp
%>

<!-- #include file="cnOpen.asp" -->

<% 
'*****数据库查询及输出字符串定义部分***********************
Dim rsTerm,rsData
Dim strSQL
Dim year1,year2,year3

year1 = CInt(Session("yYear1"))
year2 = CInt(Session("yYear2"))
year3 = CInt(Session("yYear3"))

Set rsTerm = Server.CreateObject("ADODB.RecordSet")
Set rsData = Server.CreateObject("ADODB.RecordSet")

If Session("Type") = "Term" Then
  strSQL = "SELECT TermNo FROM TermTable WHERE TermName='"&Session("Name")&"'"
ElseIf Session("Type") = "Buss" Then
  strSQL = "SELECT TermNo FROM TermTable WHERE BussName='"&Session("Name")&"'"
ElseIf Session("Type") = "Line" Then
  strSQL = "SELECT TermNo FROM TermTable WHERE LineName='"&Session("Name")&"'"
ElseIf Session("Type") = "All" Then
  strSQL = "SELECT TermNo FROM TermTable"
End If    
      
rsTerm.Open strSQL,cn
Do While Not rsTerm.Eof

  '取第一年数据
  rsData.Open "SELECT * FROM YearDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
    "DataYear="&year1,cn       
  If Not rsData.Eof Then
    For i = 1 to xNum 
      strField = "Data"&Cstr(i)
      If Not IsNull(rsData(strField)) Then 
        yArray1(i) = yArray1(i)+rsData(strField)
      End if
    Next
  End if
  rsData.Close

  '取第二年数据
  rsData.Open "SELECT * FROM YearDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
    "DataYear="&year2,cn       
  If Not rsData.Eof Then
    For i = 1 to xNum 
      strField = "Data"&Cstr(i)
      If Not IsNull(rsData(strField)) Then 
        yArray2(i) = yArray2(i)+rsData(strField)
      End if
    Next
  End if
  rsData.Close
  
  '取第三年数据
  rsData.Open "SELECT * FROM YearDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
    "DataYear="&year3,cn       
  If Not rsData.Eof Then
    For i = 1 to xNum 
      strField = "Data"&Cstr(i)
      If Not IsNull(rsData(strField)) Then 
        yArray3(i) = yArray3(i)+rsData(strField)
      End if
    Next
  End if
  rsData.Close
  
  rsTerm.MoveNext
Loop

rsTerm.Close
Set rsTerm = Nothing
Set rsData = Nothing

yMax=yArray1(1)
yMin=yArray1(1)
For i = 1 To 12
  If yMin > yArray1(i) Then yMin = yArray1(i)
  If yMax < yArray1(i) Then yMax = yArray1(i)
  If yMin > yArray2(i) Then yMin = yArray2(i)
  If yMax < yArray2(i) Then yMax = yArray2(i)
  If yMin > yArray3(i) Then yMin = yArray3(i)
  If yMax < yArray3(i) Then yMax = yArray3(i)
Next
   
strDate1=year1
strDate2=year2
strDate3=year3
%>

<% '*****数据库查询及参数数组设置工作完成,进行画图工作*******
Dim img   
Set img = Server.CreateObject("myImage.Image")
img.width = xLeft+xRight+xNum*xWidth   '图形总宽=x轴总长+左部空白+右部空白
img.height = yTop+yNum*yWidth+yButtom  '图形总高=y轴总长+上部空白+下部空白
img.Clear img.RGB(255,255,255)         '设置图形颜色为白色

'设定画笔颜色
img.PenColor = img.clBlack

 '建立Y轴
img.Line xLeft,yTop-20,xLeft,yTop+yNum*yWidth
   
'Y轴小箭头
img.Line xLeft-0.5,yTop-20,xleft-5.5,yTop-10
img.Line xLeft+0.5,yTop-20,xleft+5.5,yTop-10
   
'建立X轴
img.Line xLeft,yTop+yNum*yWidth,xLeft+xWidth*xNum+20,yTop+yNum*yWidth
   
'X轴小箭头
img.Line xLeft+xWidth*xNum+20,yTop+yNum*yWidth-0.5,xLeft+xWidth*xNum+10,_
   yTop+yNum*yWidth-5.5
img.Line xLeft+xWidth*xNum+20,yTop+yNum*yWidth+0.5,xLeft+xWidth*xNum+10,_
   yTop+yNum*yWidth+5.5

'间隔为yWidth在横向上画yNum条直线
For i = yTop To yTop+yNum*yWidth Step yWidth
  img.Line xLeft,i,xLeft+xWidth*xNum,i
Next
   
'间隔为xWidth在纵向上画xNum条直线
For i = xLeft To xLeft+xNum*xWidth Step xWidth 
  img.Line i,yTop,i,yTop+yNum*yWidth
Next

'定义字体大小
img.FontSize = 8
img.FontColor = img.clBlack

'写入横坐标刻度
For i = xMin To xMax  
  If i < 10 Then 
   strTemp = "0"&i
  Else 
    strTemp = i
  End If 
  img.TextOut (i-1)*xWidth+XLeft-6,yTop+yNum*yWidth+5,strTemp
Next
      
'写入横坐标单位
img.TextOut xLeft+xWidth*xNum+2,yTop+yNum*yWidth-20,"单位:"&xUnit
     
'写入纵坐标刻度
yIncrement = (yMax*1.1-yMin*0.9)/yNum
for i=yTop+yWidth*yNum-6 to yTop-6 step -yWidth  
  strTemp = CStr(Clng(yMax*1.1-((i+6)-yTop)/yWidth*yIncrement))
  img.DrawText 1,i,xLeft-20,i+15,strTemp,img.daRight
next

'防止零除
If yIncrement = 0 Then yIncrement = 1 
      
'写入纵坐标单位
img.TextOut 1,1,"单位:"&yUnit

'输出时间标志字符串
img.FontSize = 8
img.FontColor = img.clRed
img.TextOut xLeft+xNum*xWidth+4,yTop+10,strDate1
img.FontColor = img.clBlue
img.TextOut xLeft+xNum*xWidth+4,yTop+40,strDate2
img.FontColor = img.clGreen
img.TextOut xLeft+xNum*xWidth+4,yTop+70,strDate3

'输出图片标题
strTitle = Session("name")&"年12点数据棒图"
img.FontColor = img.clBlack
img.FontSize = 12
img.DrawText xLeft,10,xLeft+xWidth*xNum,30,strTitle,img.daCenter

img.BrushStyle = img.bsSolid

'设置第一条棒图为红色并输出
img.BrushColor = img.clRed
For i = 1 To xNum
  img.FillRect xLeft+(i-1)*xWidth-15,yTop+yWidth*yNum,xLeft+(i-1)* _
    xWidth-5,yTop+yNum*yWidth-(yArray1(i)-yMin*0.9)*yWidth/yIncrement
Next

'设置第二条棒图为蓝色并输出
img.BrushColor = img.clBlue
For i = 1 To xNum
  img.FillRect xLeft+(i-1)*xWidth-5,yTop+yWidth*yNum,xLeft+(i-1)* _
    xWidth+5,yTop+yNum*yWidth-(yArray2(i)-yMin*0.9)*yWidth/yIncrement
Next

'设置第三条棒图为绿色并输出
img.BrushColor = img.clGreen
For i = 1 To xNum
  img.FillRect xLeft+(i-1)*xWidth+5,yTop+yWidth*yNum,xLeft+(i-1)* _
    xWidth+15,yTop+yNum*yWidth-(yArray3(i)-yMin*0.9)*yWidth/yIncrement
Next

img.JPEGQuality = 100
Response.BinaryWrite img.JPEGImage
Set img = Nothing
%>

<!-- #include file="cnClose.asp" -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -