NOTÍCIA

Criando um gráfico de barras a partir de arrays


Este Script é uma função
que cria um gráfico de barras, a partir de arrays.

<%@ Language=VBScript
%>
<%

function makechart(title, numarray, labelarray, imagename,
maxheight, maxwidth, addvalues)

‘title: Título do Grafico
‘numarray: Uma Array de valores para montar o Gráfico

‘labelarray: Uma Array com os títulos dos valores passados
pela Array numarray
‘imagename: Nome da imagem a ser utilizada para construir
o gráfico. Utilize um Gif de 1 pixel da cor que você
preferir…
‘maxheight: Altura do Gráfico, sem contar os títulos
dos valores
‘maxwidth: Largura de cada coluna
‘addvalues: True ou False. Se vc quer que os valores
apareçam ou não no gráfico
‘para usar esta função: response.write makechart(parameters)

dim tablestring
dim max
dim tempnumarray
dim templabelarray
dim heightarray
dim tempnum

if maxheight > 0 and maxwidth > 0 and ubound(labelarray)
= ubound(numarray) then

templabelarray = labelarray
tempnumarray = numarray
heightarray = array()
max = 0
maxlength = 0
tablestring = “<TABLE>” & vbCrLf

for each stuff in tempnumarray
if stuff > max then max = stuff end if
next

tempnum = maxheight/max

for counter = 0 to ubound(tempnumarray)
if tempnumarray(counter) = max then
redim preserve heightarray(counter)
heightarray(counter) = maxheight
else
redim preserve heightarray(counter)
heightarray(counter) = tempnumarray(counter) * tempnum

end if
next

tablestring = tablestring & “<TR><TH colspan='”
& ubound(tempnumarray)+1 & “‘>” & title
& “</TH></TR>” & _
vbCrLf & “<TR>” & vbCrLf
for counter = 0 to ubound(tempnumarray)
tablestring = tablestring & vbTab & “<TD
valign=’bottom’ align=’center’><img src='” &
imagename & “‘ width='” & maxwidth & “‘
height='” & _
heightarray(counter) & “‘>”
if addvalues then
tablestring = tablestring & “<BR>” & tempnumarray(counter)

end if
tablestring = tablestring & “</TD>” &
vbCrLf
next

tablestring = tablestring & “</TR>” &
vbCrLf

for each stuff in labelarray
tablestring = tablestring & vbTab & “<TD
align=’center’><B>    ” & stuff
& ”    </TD>” & vbCrLf
next

tablestring = tablestring & “</TABLE>” &
vbCrLf
makechart = tablestring
else
Response.Write “Erro! A altura e a largura devem ser
maiores que zero (0), ou o número de títulos não é igual
ao número de valores passados…”
end if
end function
%>

<HTML↳HTML45 conteúdosA importância do HTML e CSS para quem trabalha com UI Design e Design SystemProduto & UX · dez 2024Como hostear seu site HTML gratuitamente com GitHub PagesDev (Back & Front) · jun 2025SQL Server – Como criar um versionamento de código das suas Stored Procedures em HTML e com comentários da alteraçãoData · nov 2020Ver tudo em Dev (Back & Front) →>
<HEAD>
<TITLE>CHART</TITLE>
</HEAD>
<BODY>
<%
dim stuff
stuff = Array(200,100,50,74,23.3)
labelstuff = Array(“Campo1″,”Campo2″,”fff”,”ggg”,”gggg”)

Response.Write makechart(“Meu Gráfico”, stuff, labelstuff,
“chart.gif”, 50, 10, true)
%>
</BODY>
</HTML>

Matérias especiais e reportagens conduzidas internamente pela Redação iMasters. Acompanhe no Twitter @imasters e no Instagram/Threads @portalimasters

Mais de Redação iMasters
Ver perfil →