专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » vml柱状图:ASP结合VML生成柱状图 »正文

vml柱状图:ASP结合VML生成柱状图

来源: 发布时间:星期四, 2009年2月12日 浏览:218次 评论:0


<%

’ 介绍说明此代码根据网络上相关代码修改而成.根据数据库数据动态生成柱状图表
’ 数据结构:tblCart(str,long)

Dim strConn,strDBPath
strDBPath = \"db1.mdb\"
strConn = \"Provider=Microsoft.Jet.Oledb.4.0;Data Source=\" & Server.MapPath(strDBPath)

Set objConn = Server.CreateObject(\"ADODB.Connection\")
objConn.Open strConn

Set objRs = Server.CreateObject(\"ADODB.Record\")
strSQL = \"SELECT * FROM tblChart\"
objRs.Open strSQL,objConn, 3, 2

total_no = objRs.RecordCount

Redim total(total_no,2)
Dim i
i = 0
While Not objRs.EOF
i = i + 1
total(i,1) = Trim(objRs.Fields(2).Value)
total(i,2) = Trim(objRs.Fields(1).Value)
objRs.MoveNext
Wend

If objRs.State = adStateOpen Then objRs.Close : Set objRs = Nothing
If objConn.State = adStateOpen Then objConn.Close : Set objConn = Nothing
%>
<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">
<!--[If !mso]>
<style>
v:* { behavior: url(#default#VML) }
o:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
<![end]-->
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; char=gb2312\">
<title></title>
<style>
TD { FONT-SIZE: 9pt}
</style></head>
<body topmargin=5 leftmargin=0 scroll=AUTO>
<%Call createHistogram(total,200,20,20,30,400,200,\"A\")%>
<%Call createHistogram(total,200,320,20,20,400,250,\"B\")%>
</body>
</html>
<%
Function createHistogram(total,table_x,table_y,thickness,table_width,all_width,all_height,table_type)
’参数含义(传递横坐标纵坐标柱子厚度柱子宽度图表宽度图表高度,图表类型)
’纯ASP代码生成图表1——柱状图

strColor = \"d1ffd1,ffbbbb,ffe3bb,cff4f3,d9d9e5,ffc7ab,ecffb7,00ff00,ff0000,ff9900,33cccc,666699,993300,99cc00\"
arrColor = Split(strColor,\",\")

Redim tb_color(total_no,2)
Dim j
’Response.Write \"Ubound(tb_color)=\" & Ubound(tb_color)
For j = 1 To Ubound(tb_color)

Randomize ’化随机数生成器 [Page]
rndValue = Int((13 * Rnd) + 1)
If rndValue = 13 Then rndValue = 12
tb_color(j,1)=\"#\" & arrColor(rndValue)’\"#d1ffd1\"
tb_color(j,2)=\"#\" & arrColor(rndValue+1)’\"#00ff00\"

Next

line_color=\"#69f\"
left_width=70
length=thickness/2
total_no=Ubound(total,1)

temp1=0
For i=1 To total_no
If temp1 < CLng(total(i,1)) Then temp1=CLng(total(i,1))
Next
temp1=CInt(temp1)
If temp1>9 Then
temp2=mid(cstr(temp1),2,1)
If temp2 > 4 Then
temp3=((temp1/(10^(len(cstr(temp1))-1)))+1)*10^(len(cstr(temp1))-1)
Else
temp3=((temp1/(10^(len(cstr(temp1))-1)))+0.5)*10^(len(cstr(temp1))-1)
End If
Else
If temp1 > 4 Then temp3=10 Else temp3=5
End If
temp4=temp3

Response.write \"<!--[If gte vml 1]><v:rect id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:\"&table_x+left_width&\"px;top:\"&table_y&\"px;width:\"&all_width&\"px;height:\"

&all_height&\"px;z-index:-1’ fillcolor=’#9cf’ stroked=’f’><v:fill rotate=’t’ angle=’-45’ focus=’100%’ type=’gradient’/></v:rect><![end]-->\"
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width&\"px,\"&table_y+all_height&\"px’ To=’\"&table_x+all_width+left_width&\"px,\"&table_y+all_height&\"px’/><![end]-->\"


Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width&\"px,\"&table_y&\"px’ To=’\"&table_x+left_width&\"px,\"&table_y+all_height&\"px’/><![end]-->\" [Page]

Select Case table_type
Case \"A\"
table_space=(all_width-table_width*total_no)/total_no
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+length&\"px,\"&table_y&\"px’ To=’\"&table_x+left_width+length&\"px,\"&table_y+all_height-length&\"px’ strokecolor=’\"&line_color&\"’/>

<![end]-->\" & VbCrLf
For i=0 To all_height-1 step all_height/5
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width&\"px,\"&table_y+all_height-length-i&\"px’ To=’\"&table_x+left_width+length&\"px,\"&table_y+all_height-i&\"px’ strokecolor=’\"&line_color&\"’/><![end]-->\" & VbCrLf
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+length&\"px,\"&table_y+all_height-length-i&\"px’ To=’\"&table_x+all_width+left_width&\"px,\"&table_y+all_height-length-i&\"px’ strokecolor=’\"&line_color&\"’/><![end]-->\" & VbCrLf
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+(left_width-15)&\"px,\"&table_y+i&\"px’ To=’\"&table_x+left_width&\"px,\"&table_y+i&\"px’/><![end]-->\" & VbCrLf
Response.write \"<!--[If gte vml 1]>\" & VbCrLf
Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&table_x&\"px;top:\"&table_y+i&\"px;width:\"&left_width&\"px;height:18px;z-index:1’>[Page]

\" & VbCrLf
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’right’>\"&temp4&\"</td></tr></table></v:textbox></v:shape><![end]-->\" & VbCrLf
temp4=temp4-temp3/5
Next

For i=1 To total_no
temp_space=table_x+left_width+table_space/2+table_space*(i-1)+table_width*(i-1)
Response.write \"<v:rect id=’_x0000_s1025’ alt=’’ style=’position:absolute;left:\"
Response.write temp_space
Response.write \"px;top:\"
Response.write table_y+all_height*(1-(total(i,1)/temp3))
Response.write \"px;width:\"&table_width&\"px;height:\"&all_height*(total(i,1)/temp3)&\"px;z-index:1’ fillcolor=’\"&tb_color(i,2)&\"’>\" & VbCrLf
Response.write \"<v:fill color2=’\"&tb_color(i,1)&\"’ rotate=’t’ type=’gradient’/>\" & VbCrLf
Response.write \"<o:extrusion v:ext=’view’ backdepth=’\"&thickness&\"pt’ color=’\"&tb_color(i,2)&\"’ _disibledevent=>


Response.write \"</v:rect>\" & VbCrLf
Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&temp_space&\"px;top:\"&table_y+all_height*(1-(total(i,1)/temp3))-table_width&\"px;width:\"&table_space+15&\"px;height:18px;z-index:1’>\" [Page]
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’center’>\"&total(i,1)&\"</td></tr></table></v:textbox></v:shape>\" & VbCrLf
Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&temp_space-table_space/2&\"px;top:\"&table_y+all_height+1&\"px;width:\"&table_space+table_width&\"px;height:18px;z-index:1’>\"
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’center’>\"&total(i,2)&\"</td></tr></table></v:textbox></v:shape>\" & VbCrLf
Next
Case \"B\"
table_space=(all_height-table_width*total_no)/total_no
temp4=temp3/5
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+length&\"px,\"&table_y+all_height-length&\"px’ To=’\"&table_x+left_width+all_width&\"px,\"&table_y+all_height-length&\"px’ strokecolor=’\"&line_color&\"’/><![end]-->\"
For i=0 To all_width-1 step all_width/5
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+i&\"px,\"&table_y+all_height-length&\"px’ To=’\"&table_x+left_width+length+i&\"px,\"&table_y+all_height&\"px’ strokecolor=’\"&line_color&\"’/><![end]-->\"
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+length+i&\"px,\"&table_y+all_height-length&\"px’ To=’\"&table_x+left_width+length+i&\"px,\"&table_y&\"px’ strokecolor=’\"&line_color&\"’/><![end]-->\" [Page]
Response.write \"<!--[If gte vml 1]><v:line id=’_x0000_s1027’ alt=’’ style=’position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1’ from=’\"&table_x+left_width+i+all_width/5&\"px,\"&table_y+all_height&\"px’ To=’\"&table_x+left_width+i+all_width/5&\"px,\"&table_y+all_height+15&\"px’/><![end]-->\"
Response.write \"<!--[If gte vml 1]>\"
Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&table_x+left_width+i+all_width/5-left_width&\"px;top:\"&table_y+all_height&\"px;width:\"&left_width&\"px;height:18px;z-index:1’>\"
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’right’>\"&temp4&\"</td></tr></table></v:textbox></v:shape><![end]-->\"
temp4=temp4+temp3/5
Next



For i=1 To total_no
temp_space=table_space/2+table_space*(i-1)+table_width*(i-1)
Response.write \"<v:rect id=’_x0000_s1025’ alt=’’ style=’position:absolute;left:\"
Response.write table_x+left_width
Response.write \"px;top:\"
Response.write table_y+temp_space
Response.write \"px;width:\"&all_width*(total(i,1)/temp3)&\"px;height:\"&table_width&\"px;z-index:1’ fillcolor=’\"&tb_color(i,2)&\"’>\" [Page]
Response.write \"<v:fill color2=’\"&tb_color(i,1)&\"’ rotate=’t’ angle=’-90’ focus=’100%’ type=’gradient’/>\"
Response.write \"<o:extrusion v:ext=’view’ backdepth=’\"&thickness&\"pt’ color=’\"&tb_color(i,2)&\"’ _disibledevent=> Response.write \"</v:rect>\"
Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&table_x+left_width+all_width*(total(i,1)/temp3)+thickness/2&\"px;top:\"&table_y+temp_space&\"px;width:\"&table_space+15&\"px;height:18px;z-index:1’>\"
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’center’>\"&total(i,1)&\"</td></tr></table></v:textbox></v:shape>\"

Response.write \"<v:shape id=’_x0000_s1025’ type=’#_x0000_t202’ alt=’’ style=’position:absolute;left:\"&table_x&\"px;top:\"&table_y+temp_space&\"px;width:\"&left_width&\"px;height:18px;z-index:1’>\"
Response.write \"<v:textbox in=’0px,0px,0px,0px’><table cellspacing=’3’ cellpadding=’0’ width=’100%’ height=’100%’><tr><td align=’right’>\"&total(i,2)&\"</td></tr></table></v:textbox></v:shape>\"
Next
Case Else
End Select

End Function
%>

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: