挺奇怪的,为什么想将数据库中城市(city)名称显示在canvas图上就不行呢?
该代码的测试网页:www.iescm.com/net56/drawtest1.asp
代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试</title>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" bgcolor="#C9DBEF">
<div align="center">
<form name=form1 action="questionBrowse" method=post>
<table border="2" width="980" bordercolor="#C9DBEF" height="100%" >
<tr valign=top>
<td>
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td>
<p align="center">信息浏览
</td>
<td>
<p align="center">信息浏览
</td>
</tr>
<tr>
<td>
<div align="center">
<table border="1" width="100%" cellspacing="0" cellpadding="0" id="table2">
<tr bgcolor="#9999FF">
<td align="center"><b><font color="#000080">地名</font></b></td>
<td align="center"><b><font color="#000080">x坐标</font></b></td>
<td align="center"><b><font color="#000080">y坐标</font></b></td>
</tr>
<%
dim objConn,ObjRS,strSQL,strSQLx,strSQLy,maxX,maxY,minX,minY
set objConn=nothing
db="data/net56.mdb"
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath(db)
objConn.Open
set objRS=Server.CreateObject("ADODB.Recordset")
strSQL="Select max(xpos) as xxxx from coordinates where province='安徽省'"
ObjRS.Open strSQL,objConn,3,2
maxX=objRS("xxxx")
response.write(maxX)
objRS.Close
strSQL="Select min(xpos) as xxxx from coordinates where province='安徽省'"
ObjRS.Open strSQL,objConn,3,2
minX=objRS("xxxx")
'response.write(minX)
objRS.Close
strSQL="Select max(ypos) as xxxx from coordinates where province='安徽省'"
ObjRS.Open strSQL,objConn,3,2
maxY=objRS("xxxx")
'response.write(maxY)
objRS.Close
strSQL="Select min(ypos) as xxxx from coordinates where province='安徽省'"
ObjRS.Open strSQL,objConn,3,2
minY=objRS("xxxx")
'response.write(minY)
objRS.Close
strSQL="Select * from coordinates where province='安徽省' order by xpos asc"
ObjRS.Open strSQL,objConn,3,2
do while not ObjRS.eof
%>
<tr bordercolorlight=#3366CC>
<td width="" height="10"><%=objRS("city")%></td>
<td width="" height="10"><%=objRS("xPos")%></td>
<td width="" height="10"><%=objRS("yPos")%></td>
</tr>
<%
objRS.moveNext
loop
objRS.moveFirst
%>
</table>
</div>
</td>
<td>
<!--绘图 -->
<canvas id="myCanvas" width="400" height="400" style="border:1px solid #c3c3c3;">
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var x,y,minXx,maxXx,minYy,maxYy;
minXx=<%=minX%>;
maxXx=<%=maxX%>;
minYy=<%=minY%>;
maxYy=<%=maxY%>;
var cityName="中国";
x=<%=objRS("xpos")%>;
y=<%=objRS("ypos")%>;
x=(x-minXx)/(maxXx-minXx)*340+30;
y=(y-minYy)/(maxYy-minYy)*340+50;
ctx.arc(x,y,4,0,2*Math.PI);
ctx.font="12px Arial";
ctx.fillText(cityName,x+5,y);
ctx.moveTo(x,y);
</script>
<%
for i=1 to objRS.recordCount-1
objRS.moveNext
%>
<script type=text/javascript>
x=<%=objRS("xpos")%>;
y=<%=objRS("ypos")%>;
x=(x-minXx)/(maxXx-minXx)*340+30;
y=(y-minYy)/(maxYy-minYy)*340+50;
ctx.strokeStyle="#FF0000";
ctx.lineTo(x,y);
ctx.arc(x,y,4,0,2*Math.PI);
document.write(<%=objRS("city")%>);
</script>
<% next %>
<script>
ctx.stroke();
</script>
<%
objRS.Close
Set objRS=nothing
objConn.Close
Set objConn=nothing
%>
</td>
</tr>
</table>
</td></tr>
<tr>
<td>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>