Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make a graph 1

Status
Not open for further replies.

nk9100

Technical User
May 13, 2005
67
GB
I am wondering if it would be possible to make a graph dependant on values in a DB and display that for each user?, so If I have 0,1,2,3 in a DB, and the graph is displayed either by clicking a button, or loaded onto the page directly, is it difficult?

Life is a journey that always ends up in the place
 
Thanks, I will check it out

Life is a journey that always ends up in the place
 
Bar charts are quite simple.
If you make a gif a few pixels wide and 1px high and then in your asp associate the height attribute to a value from your db.

for example.

Code:
<%'first get the heighest value
max = heigest value

'your loop start
barHeight = max / rs("dbvalue")*100 'this will make the maximum value 100px high
%>
<img src="1px.gif" height="<%=barHeight%>" alt="<%=rs("dbvalue")*%>" />
<%'your loop ends here%>
does that make sense!?
 
here is a modified script i use, may help you a bit
you will need this file, unzip it and put it with the asp page (the images go in a folder called graph.)
Code:
<%call chart("Apple,Pear,Mango,Bannana,Other","1,3,6,7,20",5)%>
<%sub chart(arrNames,arrValues,records)
const x = 0
const y = 1
arrValues=cArr(arrValues)
arrNames=cArr(arrNames)
For i=0 To UBound(arrValues)
  intNumberSold = cint(arrValues(i))

  If intNumberSold > max Then
    max = intNumberSold
  End If
Next
%>
	<table cellspacing="0">
	<tr>
	<td>
	<div style="border-left:1px solid #000000;margin:10px;">

		<%
		if ubound(arrValues) >= records-1 then
			records = records
		else
			records = ubound(arrValues)
		end if
		for n=0 to records-1 
			height = (round(cint(arrValues(n))/max *100))%>
			<img src="graph/blank.gif" width="8" style="border-bottom:1px solid #000000;margin-left:-4px;" /><img src="graph/<%=n%>.gif" height="<%=height%>" width="8" style="border-bottom:1px solid #000000;" alt="<%=arrValues(n)%>" />
		<%next%>
			<img src="graph/blank.gif" width="8" style="border-bottom:1px solid #000000;margin-left:-4px;" />
	</div>
	</td>
	<td>
	<div style="padding-left:20px;">
		<%for n=0 to records-1 %>
			<img src="graph/<%=n%>.gif" height="8" width="8" alt="<%=arrValues(n)%>"  /> <%=arrNames(n)%><br />
		<%next%>
	</div>
	</td>
	</tr>
	</table>
<%end sub%>
<%
function cArr(str)
	if not isArray(str) then
		cArr = split(str, ",")
	else
		cArr = str
	end if
end function
%>
 
Thanks alot!

That looks pretty cool

I will try it out, and post results back

Thanks again.

Life is a journey that always ends up in the place
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top