📄 monthpowergraph.asp
字号:
<%
'**********以下数据由绘图程序动态确定***********************
'横纵坐标点数
Const xNum = 31
Const yNum = 10
'横纵坐标间距
Const xWidth = 20
Const yWidth = 20
'横,纵坐标单位
Const xUnit = "日"
Const yUnit = "KW"
'横坐标最大值最小值
Const xMin = 1
Const xMax = 31
'坐标周围所留空白用以显示字符串
Const xLeft = 40
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
%>
<%
'定义一个函数,用来根据年份和月份求取该月天数
Function DayNum(intYear,intMonth)
Dim dayArray
dayArray = Array(31,28,31,30,31,30,31,31,30,31,30,31)
If intMonth = 2 Then
If intYear mod 4 = 0 Then
DayNum = 29
Else
DayNum = 28
End If
Else
DayNum = dayArray(intMonth-1)
End If
End Function
%>
<!-- #include file="cnOpen.asp" -->
<%
'*****数据库查询及输出字符串定义部分***********************
Dim rsTerm,rsData
Dim strSQL
Dim year1,year2,year3,month1,month2,month3
year1 = CInt(Session("mYear1"))
year2 = CInt(Session("mYear2"))
year3 = CInt(Session("mYear3"))
month1 = CInt(Session("mMonth1"))
month2 = CInt(Session("mMonth2"))
month3 = CInt(Session("mMonth3"))
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 MonthDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
"DataYear="&Session("mYear1")&" AND DataMonth="&Session("mMonth1"),cn
If Not rsData.Eof Then
For i = 1 to DayNum(year1,month1)
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 MonthDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
"DataYear="&Session("mYear2")&" AND DataMonth="&Session("mMonth2"),cn
If Not rsData.Eof Then
For i = 1 to DayNum(year2,month2)
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 MonthDataTable WHERE TermNo="&rsTerm(0)&" AND "&_
"DataYear="&Session("mYear3")&" AND DataMonth="&Session("mMonth3"),cn
If Not rsData.Eof Then
For i = 1 to DayNum(year3,month3)
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 DayNum(year1,month1)
If yMin > yArray1(i) Then yMin = yArray1(i)
If yMax < yArray1(i) Then yMax = yArray1(i)
Next
For i = 1 To DayNum(year2,month2)
If yMin > yArray2(i) Then yMin = yArray2(i)
If yMax < yArray2(i) Then yMax = yArray2(i)
Next
For i = 1 To DayNum(year3,month3)
If yMin > yArray3(i) Then yMin = yArray3(i)
If yMax < yArray3(i) Then yMax = yArray3(i)
Next
strDate1=Session("mYear1")&"-"&Session("mMonth1")
strDate2=Session("mYear2")&"-"&Session("mMonth2")
strDate3=Session("mYear3")&"-"&Session("mMonth3")
%>
<% '*****数据库查询及参数数组设置工作完成,进行画图工作*******
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 = Clng(yMax*1.1-((i+6)-yTop)/yWidth*yIncrement)
img.DrawText 1,i,xLeft-10,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")&"月31点数据曲线图"
img.FontColor = img.clBlack
img.FontSize = 12
img.DrawText xLeft,10,xLeft+xWidth*xNum,30,strTitle,img.daCenter
'设置第一条数据线为红色并输出
img.ClearPoint
For i = 1 To DayNum(year1,month1)
img.SetPoint xLeft+(i-1)*xWidth,_
yTop+yNum*yWidth-(yArray1(i)-yMin*0.9)*yWidth/yIncrement
Next
img.PenColor=img.clRed
img.PolyLine
'设置第二条数据线为蓝色并输出
img.ClearPoint
For i = 1 To DayNum(year2,month2)
img.SetPoint xLeft+(i-1)*xWidth,_
yTop+yNum*yWidth-(yArray2(i)-yMin*0.9)*yWidth/yIncrement
Next
img.PenColor = img.clBlue
img.PolyLine
'设置第三条数据线为绿色并输出
img.ClearPoint
For i = 1 To DayNum(year3,month3)
img.SetPoint xLeft+(i-1)*xWidth,_
yTop+yNum*yWidth-(yArray3(i)-yMin*0.9)*yWidth/yIncrement
Next
img.PenColor = img.clGreen
img.PolyLine
img.JPEGQuality = 100
Response.BinaryWrite img.JPEGImage
Set img = Nothing
%>
<!-- #include file="cnClose.asp" -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -