Bargraph in ASP

Thursday Jun 10th 1999 by ServerWatch Staff
Share:

Now lets make a simple bargraph with asp. We start with thebasic HTML Tags and the opening of the database and recordset. This time we dont use a DSN but the actual database itself.

by Armand Datema

Now lets make a simple bargraph with asp. We start with thebasic HTML Tags and the opening of the database and recordset. This time we dont use a DSN but the actual database itself.

<html>
<head>
</head>
<body>
<div align="center"><%
curDir = Server.MapPath("graph.mdb")
'Create the Database Connection
Set con = Server.CreateObject("ADODB.Connection")
con.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"

Now lets open the recordset and run the query

set conntemp=server.createobject("adodb.connection")
Set rs = server.createobject("adodb.recordset")
rs.Open "select * from graph", con
do While not rs.EOF %>

Now all you need to do is make te height of the image the content of the recordsource like this height="<%=rs("1998")%>

One final note: make sure you set the alignment of the images to bottom. Otherwise the images will be centered in the middle of the table, and wont allign correctly.

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" bgcolor="#FFFFFF" valign="bottom"><img src="green.gif" width="100"
height="<%=rs("1998")%>"   align="absbottom"></td>
<td width="33%" bgcolor="#FFFFFF" valign="bottom"><img src="red.gif" width="100"
height="<%=rs("1999")%>"   align="absbottom"></td>
<td width="34%" bgcolor="#FFFFFF" valign="bottom"><img src="yellow.gif" width="100"
height="<%=rs("2000")%>"   align="absbottom"></td>
</tr>
<tr>
<td width="33%" align="center" bgcolor="#FFFFFF">1998</td>
<td width="33%" align="center" bgcolor="#FFFFFF">1999</td>
<td width="34%" align="center" bgcolor="#FFFFFF">Y2K</td>
</tr>
</table>

And at last we close our HTML tags and ASP code

</center></div><%
rs.moveNext
loop
%>
</div>
</body>
</html>

This completes yer ASP page, look below for the complete code of imagedbase.asp

<html>
<head>
</head>

<body>
<div align="center"><%
curDir = Server.MapPath("graph.mdb")
'Create the Database Connection
Set con = Server.CreateObject("ADODB.Connection")
con.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
set conntemp=server.createobject("adodb.connection")
Set rs = server.createobject("adodb.recordset")
rs.Open "select * from graph", con
do While not rs.EOF %>
<div align="center"><center>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" bgcolor="#FFFFFF" valign="bottom"><img src="green.gif" width="100"
height="<%=rs("1998")%>" align="absbottom"></td>
<td width="33%" bgcolor="#FFFFFF" valign="bottom"><img src="red.gif" width="100"
height="<%=rs("1999")%>"   align="absbottom"></td>
<td width="34%" bgcolor="#FFFFFF" valign="bottom"><img src="yellow.gif" width="100"
height="<%=rs("2000")%>"   align="absbottom"></td>
</tr>
<tr>
<td width="33%" align="center" bgcolor="#FFFFFF">1998</td>
<td width="33%" align="center" bgcolor="#FFFFFF">1999</td>
<td width="34%" align="center" bgcolor="#FFFFFF">Y2K</td>
</tr>
</table>
</center></div><%
rs.moveNext
loop
%>
</div>
</body>
</html>

 

Download Code
Bargraph

light.gif (1591 bytes)

Note: Here you will find extra information regarding the article. It could be additions, aprovements, links to other resources or other methods of resolving this problem. If you were looking for the code, go click the diskette to download it.

ASP101 Has a number of codes with other ways of making bargraphs with ASP. Go check em out.


Back to the Article


Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved