<% option explicit %>
<html>
<head>
<title>利用owc画图的例子</title>
<!– #include virtual="/include/adovbs.inc" –>
<%
function exportcharttogif(objcspace, strabsfilepath, strrelfilepath)
dim strfilename
randomize
strfilename = timer & rnd & ".gif"
objcspace.exportpicture strabsfilepath & "\" & strfilename, "gif", 600, 350
exportcharttogif = strrelfilepath & "/" & strfilename
end function
sub cleanupgif(gifpath)
dim objfs
dim objfolder
dim gif
set objfs = server.createobject("scripting.filesystemobject")
set objfolder = objfs.getfolder(gifpath)
for each gif in objfolder.files
if instr(gif.name, ".gif") > 0 and datediff("n", gif.datelastmodified, now) > 10 then
objfs.deletefile gifpath & "\" & gif.name, true
end if
next
set objfolder = nothing
set objfs = nothing
end sub
%>
</head>
<body bgcolor="#ffffff">
<%
dim objchartspace
dim objchart
dim objseries
dim objconn
dim objrs
dim c
dim series
dim strchartabspath
dim strchartrelpath
dim strchartfile
strchartabspath = server.mappath("/mypath/temp")
strchartrelpath = "temp"
set objchartspace = server.createobject("owc.chart")
set objchart = objchartspace.charts.add()
set c = objchartspace.constants
objchart.type = c.chcharttypelinemarkers
objchart.haslegend = true
set objconn = server.createobject("adodb.connection")
objconn.open "provider=sqloledb;data source=myserver;initial catalog=testdb;user id=myuid;password=mypswd;"
set objrs = server.createobject("adodb.recordset")
set objrs.activeconnection = objconn
objrs.cursortype = adopenstatic
objrs.cursorlocation = aduseclient
objrs.open "select * from testscore order by test"
set objchartspace.datasource = objrs
objchart.setdata c.chdimseriesnames, 0, "student"
for each objseries in objchart.seriescollection
objseries.setdata c.chdimcategories, 0, "test"
objseries.setdata c.chdimvalues, 0, "score"
next
for each axis in objchart.axes
axis.hastitle = true
if axis.type = c.chcategoryaxis then
axis.title.caption = "test"
else
axis.title.caption = "score"
end if
next
objchart.seriescollection(2).interior.color = "red"
objchart.seriescollection(2).line.color = "red"
strchartfile = exportcharttogif(objchartspace, strchartabspath, strchartrelpath)
response.write "<img src=""" & strchartfile & """>" & "<p>"
cleanupgif strchartabspath
objrs.close
set objrs = nothing
set objconn = nothing
set objseries = nothing
set objchart = nothing
set objchartspace = nothing
%>
</body>
</html>
