Tema: Graficos
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/06/2003, 11:00
Avatar de OooH-Boy
OooH-Boy
 
Fecha de Ingreso: marzo-2002
Mensajes: 70
Antigüedad: 23 años, 1 mes
Puntos: 0
codigo encontrado

Aqui hay un codigo que encontre me recupera los datos de una base datos pero solo recupera la lista de datos sin el query, eh estado pensando si se puede hacer la busqueda y salvarlos en otra table y luego jalarlos con este codigo. alguna idea de como puedo hacer esto por favor se aceptan ideas y si tengo que cambiar de lenguaje pues no importa lo que necesito es crear la grafica.

Aqui esta el codigo no coloco el link porque no se de donde lo encontre ok gracias..



<%
'How many pixels high we want our bar graph
Const graphHeight = 300
Const graphWidth = 450
Const barImage = "bluebar.gif"


sub BarChart(data, labels, title, axislabel)
'Print heading
Response.Write("<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0 WIDTH=" & graphWidth & ">" & chr(13))
Response.Write("<TR><TH COLSPAN=" & UBound(data) - LBound(data) + 2 & ">")
Response.Write("<FONT SIZE=+2>" & title & "</FONT></TH></TR>" & chr(13))
Response.Write("<TR><TD VALIGN=TOP ALIGN=RIGHT>" & chr(13))

'Find the highest value
Dim hi
hi = data(LBound(data))

Dim i
for i = LBound(data) to UBound(data) - 1
if data(i) > hi then hi = data(i)
next

'Print out the highest value at the top of the chart
Response.Write(hi & "</TD>")

Dim widthpercent
widthpercent = CInt((1 / (UBound(data) - LBound(data) + 1)) * 100)

For i = LBound(data) to UBound(data) - 1
Response.Write(" <TD VALIGN=BOTTOM ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
Response.Write(" <IMG SRC=""" & barImage & """ WIDTH=100% HEIGHT=" & CInt(data(i)/hi * graphHeight) & ">" & chr(13))
Response.Write(" </TD>" & chr(13))
Next

Response.Write("</TR>")
Response.Write("<TR><TD VALIGN=BOTTOM ALIGN=RIGHT>0</TD></TR>")

'Write footer
Response.Write("<TR><TD ALIGN=RIGHT VALIGN=BOTTOM>" & axislabel & "</TD>" & chr(13))
for i = LBound(labels) to UBound(labels) - 1
Response.Write("<TD VALIGN=BOTTOM ALIGN=CENTER>" & labels(i) & "</TD>" & chr(13))
next
Response.Write("</TR>" & chr(13))
Response.Write("</TABLE>")
end sub


'Open connection to database
Dim objConnection
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open "DSN=Products"

Dim strSQL
strSQL = "SELECT Name,UnitsSold FROM Products"

Dim rsProducts
Set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.Open strSQL, objConnection, adOpenStatic


Dim numRecords
numRecords = rsProducts.RecordCount

Dim unitsSoldArray(), labelArray()
Redim unitsSoldArray(numRecords)
Redim labelArray(numRecords)

Dim i
for i = 0 to numRecords-1
unitsSoldArray(i) = rsProducts("UnitsSold")
labelArray(i) = rsProducts("Name")
rsProducts.MoveNext
next

%>

<HTML>
<BODY>
<CENTER>
<% BarChart unitsSoldArray,labelArray,"Units Sold Categoria","Categorias" %>
</CENTER>
</BODY>
</HTML>

<%
rsProducts.Close
Set rsProducts = Nothing

objConnection.Close
Set objConnection = Nothing
%>