当前位置:编程学习 > asp >>

用ASP及VML实现股票走势图

答案:-->
<HTML xmlns:v>
<HEAD>
<STYLE>
v\:*{behavior:url(#default#VML);}
*{font-size:12px}
</STYLE>
</HEAD>
<BODY topmargin=0 leftmargin=0 bgcolor=#D7EEFF>

<DIV id=showdiv style="font-size:12px; Color:RED; DISPLAY: none; LEFT: 0px; PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px; POSITION: absolute; TABLE-LAYOUT: fixed; TOP: 0px; WHITE-SPACE: nowrap; Z-INDEX: 500"></DIV>
<script language="javascript">
<!--
//加速alt,title的显示
var oldtext="abc";

function window.onload(){
try{myid2.height=window.document.body.scrollHeight}
catch(e){}
}

function document.onmousemove(){
try{
if(event.srcElement.getAttribute('onMOver')){
showdiv.style.left=event.x-3;showdiv.style.top=event.y+document.body.scrollTop+18;if(event.srcElement.onMOver!=oldtext){oldtext=event.srcElement.onMOver;showdiv.innerText=oldtext;showdiv.style.backgroundColor='#FFF6FF'};if(showdiv.style.display=='none')showdiv.style.display=''
if(showdiv.style.posLeft+300>screen.width){showdiv.style.posLeft=520}
}
else{
if(showdiv.style.display=='')showdiv.style.display='none';}
}
catch(e){}
}
//-->
</SCRIPT>

<?xml:namespace prefix=v />
<%
'连接数据库
set conn=Server.CreateObject("Adodb.Connection")
connStr="Provider=SQLOLEDB;Data Source=(local);database=DBName;uid=user;pwd=pass;"
conn.Open connStr

'初始化,定义变量
BoardID=int(Request("BoardID"))
if Request("BoardID")="" then BoardID=1
PicWidth=720
PicHeight=300

'显示股票列表下拉菜单
sql="Select * from Board where BoardID in (Select BoardID From Stocks)"
set RsBoard=conn.execute(sql)
StockStr="<select onchange=""location.replace('Trend.asp?BoardID='+this.value)"">"
do while not RsBoard.eof
if RsBoard("BoardID")=BoardID then
ChkStr=" selected"
else
ChkStr=""
end if
StockStr=StockStr&"<option value="&RsBoard("BoardID")&ChkStr&">"&RsBoard("BoardName")&"</option>"
RsBoard.movenext
loop
set RsBoard=nothing
StockStr=StockStr&"<select>"
response.write StockStr

'打开股票走势表
sql="Select * from StocksTrend where BoardID="&BoardID&" and CalTime>getDate()-1 and Day(CalTime)=Day(getDate()) order by ID"
set rs=Server.CreateObject("Adodb.Recordset")
rs.Open sql,conn,1,1

'获取股票价格列表至数组,并计算最高最低价
Rec=rs.RecordCount
redim Price(Rec)
Highest=0
Lowest=9999
for i=1 to Rec
Price(i)=rs("Price")
if Price(i)>Highest then Highest=Price(i)
if Price(i)<Lowest then Lowest=Price(i)
rs.movenext
next
set rs=nothing

'画时间点,间隔6小时
for i=0 to 24 step 6
X=Round(i/24*PicWidth)
DrawLine X,PicHeight,X,PicHeight+5,"#808080"
PrintWord X,PicHeight+15,i&":00"
next

'画走势图边框
DrawLine 0,0,PicWidth,0,"#000000"
DrawLine 0,0,0,PicHeight,"#000000"
DrawLine PicWidth,0,PicWidth,PicHeight,"#000000"
DrawLine 0,PicHeight,PicWidth,PicHeight,"#000000"

'画四等分线
DrawLine 0,PicHeight*1/4,PicWidth,PicHeight*1/4,"#AAAAAA"
DrawLine 0,PicHeight*2/4,PicWidth,PicHeight*2/4,"#AAAAAA"
DrawLine 0,PicHeight*3/4,PicWidth,PicHeight*3/4,"#AAAAAA"

'标明四等分线价格
PrintWord PicWidth+15, 0/4*PicHeight, FormatNumber(Highest-(Highest-Lowest)*0/4,2,-1,0,0)
PrintWord PicWidth+15, 1/4*PicHeight, FormatNumber(Highest-(Highest-Lowest)*1/4,2,-1,0,0)
PrintWord PicWidth+15, 2/4*PicHeight, FormatNumber(Highest-(Highest-Lowest)*2/4,2,-1,0,0)
PrintWord PicWidth+15, 3/4*PicHeight, FormatNumber(Highest-(Highest-Lowest)*3/4,2,-1,0,0)
PrintWord PicWidth+15, 4/4*PicHeight, FormatNumber(Highest-(Highest-Lowest)*4/4,2,-1,0,0)

'画走势图
for i=1 to Rec
if i=1 then
SX=0
SY=0
else
SX=X
SY=Y
end if
Y=PicHeight-Round((Price(i)-Lowest)/(Highest-Lowest)*PicHeight)
X=Round((i-1)*5)
DrawPrice SX,SY,X,Y,Price(i),"#000000"
next

'自定义函数:画线
function DrawLine(SX,SY,X,Y,C)
%><v:line style="POSITION:absolute;LEFT:10;TOP:10" from="<%=SX%>,<%=SY%>" to="<%=X%>,<%=Y%>" strokecolor="<%=C%>" strokeweight="1pt"></v:line><%
response.write vbcrlf
end function

'自定义函数:画线(带alt提示功能)
function DrawPrice(SX,SY,X,Y,Price,C)
%><v:line onMOver="<%=Price%>" style="POSITION:absolute;LEFT:10;TOP:10" from="<%=SX%>,<%=SY%>" to="<%=X%>,<%=Y%>" strokecolor="<%=C%>" strokeweight="1pt"></v:line><%
response.write vbcrlf
end function

'显示文本(默认红色)
function PrintWord(X,Y,Word)
%><SPAN style="LEFT:<%=X%>;TOP:<%=Y%>;COLOR:RED;FONT-FAMILY:宋体;POSITION:absolute"><%=Word%></SPAN><%
response.write vbcrlf
end function
%>

上一个:怎样才能使得htm文件如同asp文件一样可以执行脚本代码?
下一个:读取符合RSS2.0规范的XML文档

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,