Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Vagner Nunes

Gerar Gráficos Estatísticos

Recommended Posts

olha este exemplo simples,

 

Function StatsGraph(Height)
  Dim SQL , RS

  'get last 30 records from statistics.
  SQL = "Select * from [StatsDayRel]"

  'get recordset from SQL
  Set RS = GetConn.Execute(SQL)

  Dim HTML
  HTML = HTMLGraf("Daily tips statistics", RS, 10, Height, 15) 
  StatsGraph = HTML
End Function 

'Simple HTML stacked bar graph
'2003 Antonin Foller, http://www.motobit.com
'function accepts recordset with first Next columns 
'xvalues, yvalues
'Code - code To create detail referecnce on data point
'Title - title on data point
'Counter - additional description on data point
Function HTMLGraf(ChartTitle, RS, nCols,  height, SerieWidth)
  Dim Col, Row,  cCol
  Dim XSize :XSize = 100
  Dim Colors, Prev

  'Create random colors For series.
  Colors = Array ("red", "green", "blue", "magenta", "cyan", "black", _
    "darkgray", "DARKCYAN", "BLANCHEDALMOND", "MEDIUMORCHID")
  ''redim Colors(nCols-1)
  'randomize
  'Prev = cdbl(&H33)
  'for Col=0 To nCols-1
  '  Colors(Col) = "#" & hex(&H202020 Or clng(rnd * &HFFFFFF))
  'Next
    
  
  Dim h, rh

  
  h = h & "<Table border=0 CellPadding=0 CellSpacing=0><tr><td vAlign=Bottom>"

  Dim xvalue, SerieCount
  xvalue = 0
  SerieCount = 0
  Do While Not rs.eof
    rh = "" ' clear row data value.
    
    If xvalue<>rs("xvalues") Then
      'new x-value. Write x-value data, clear SerieCount
      If xvalue<>0 Then 
        rh = rh & "<tr><td height=" & XSize 
        rh = rh & " style=writing-mode:tb-rl;font-size:7pt>  " 
        rh = rh & xvalue & "</td></tr></table>"  & vbCrLf
        rh = rh & "</td><td vAlign=Bottom>"
      End If
      
      xvalue = rs("xvalues")
      rh = rh & "<Table style=cursor:hand Height=" & (height+XSize) 
      rh = rh & " Cellpadding=0 CellSpacing=0 border=0 Width=" & SerieWidth 
      rh = rh & " title=""" & xvalue & """><tr><td></td></tr>" & vbCrLf
      SerieCount = 1
    Else
      SerieCount = SerieCount+1
    End If
    
    Dim Value, Color
    'get serie color
    Color = colors(SerieCount-1)
    'get y-value from recordset
    Value = (rs("yvalues"))

    If Value<>0 Then 
      'create data point For nonzero value.
      'the data point consists from td of Color, height is a Value, title
      'there is also counter description inside the data point (writing-mode:tb-rl)
      'td has onclick To open detail.
      rh = rh & "<tr><td vAlign=Top bgColor=" & Color & " height=" & Value & "" & " title=""" & rs("Title") 
      rh = rh & """ onclick=""openm('" & rs("Code") & "')"">"
      rh = rh & "<Div style=color:BLACK;writing-mode:tb-rl;position:absolute;font-size:7pt> " 
      rh = rh & rs("Counter") &  "</div></td></tr>"  & vbCrLf  & vbCrLf
    End If
    h = h & rh
    rs.MoveNext
  Loop
  'x-values td data 
  h = h & "<tr><td height=" & XSize & " style=writing-mode:tb-rl;font-size:7pt>  "
  h = h & xvalue & "</td></tr></table>"  & vbCrLf
  h = h & "</td></tr></table>"

  'Graph Border table
  h = "<Table border=1 CellPadding=0 CellSpacing=0 BGCOLOR=DARKSEAGREEN BORDERCOLOR=BLACK><tr><th> " & _
   ChartTitle & "</th></tr><tr><td>" & h & "</td></tr></table>"

  'Data point detail click.
  h = h & "<"+"script>function openm(id){window.open('det.asp?'+id+'.htm');};</"+"Script>"
  HTMLGraf = h
End Function

e faça uma busca no lab. de script que coloquei outros exemplos

 

<%@ Language=VBScript %>
<%

sub ShowOrderStatus(Status,graph,comment)
	Response.Write "<BR>" '& Status
	dim state,text,bgcolor
	dim bgcolor1,bgcolor2,bgcolor3,bgcolor4,bgcolor5,bgcolor6,bgcolor7,bgcolor8
	dim text1,text2,text3,text4,text5,text6,text7,text8,text0
	
	'initialize 
	state = 0
	text = ""
	bgcolor="#00FF00"
	
	'cell colors
	bgcolor0 = "#f1f1f1"
	bgcolor1 = "#00E055"
	bgcolor2 = "#22C055"
	bgcolor3 = "#44A055"
	bgcolor4 = "#668055"
	bgcolor5 = "#886055"
	bgcolor6 = "#AA4055"
	bgcolor7 = "#CC2055"
	bgcolor8 = "#EE0055"
	bgcolor9 = "#FF0000"
	
	'text messages
	text0 = "-- N.A --"		
	text1 = "Text 1"
	text2 = "Text 2"
	text3 = "Text 3"
	text4 = "Text 4"	
	text5 = "Text 5"
	text6 = "Text 6"
	text7 = "Text 7"
	text8 = "Text 8"
	text9 = "Text 9"
		
	if Status = "" or Status = Null then
		Status = 0	
	end if

	state = Status 
	text = eval("text" & Status)
	
	dim TableWidth, CellWidth
	TableWidth = "100"
	CellWidth = (TableWidth)/8	
		
	if graph = 1 then
		Response.Write "<table width="&TableWidth&" height=5 cellpadding=1 cellspacing=1 bgcolor=white class=table_border_thin>" & vbCrLf
		Response.Write "<tr align=left nowrap>" 
		
		if state <> 9 then
			IF state >=1 THEN Response.Write "<td width="&CellWidth&" title="""& text1 &""" bgcolor="& bgcolor1 &"></td>" & vbCrLf 
			IF state >=2 THEN Response.Write "<td width="&CellWidth&" title="""& text2 &""" bgcolor="& bgcolor2 &"></td>" & vbCrLf 
			IF state >=3 THEN Response.Write "<td width="&CellWidth&" title="""& text3 &""" bgcolor="& bgcolor3 &"></td>" & vbCrLf 
			IF state >=4 THEN Response.Write "<td width="&CellWidth&" title="""& text4 &""" bgcolor="& bgcolor4 &"></td>" & vbCrLf 
			IF state >=5 THEN Response.Write "<td width="&CellWidth&" title="""& text5 &""" bgcolor="& bgcolor5 &"></td>" & vbCrLf 
			IF state >=6 THEN Response.Write "<td width="&CellWidth&" title="""& text6 &""" bgcolor="& bgcolor6 &"></td>" & vbCrLf 
			IF state >=7 THEN Response.Write "<td width="&CellWidth&" title="""& text7 &""" bgcolor="& bgcolor7 &"></td>" & vbCrLf 
			IF state >=8 THEN Response.Write "<td width="&CellWidth&" title="""& text8 &""" bgcolor="& bgcolor8 &"></td>" & vbCrLf
			IF state < 8 THEN Response.Write "<td width="&(8 - state)* CellWidth &" colspan="& (8 - state) &" bgcolor="& bgcolor0 &"></td>" & vbCrLf
		else
			Response.Write "<td width="& (8)* CellWidth &" colspan=8 title="""& text9 &""" bgcolor="& bgcolor9 &"></td>" & vbCrLf
		end if
		
		Response.Write "</tr>" & vbCrLf
		Response.Write "</table>"
	end if	
	
	if comment = 1 then
		Response.Write  text 
	end if	
end sub
%>

usando :

<%
call ShowOrderStatus(4,1,0)
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Prezados,

 

Preciso da ajuda dos senhores novamente, tentei, testei e até agora não consegui criar gráficos de dados cadastrados em um banco. Nunca joguei a toalha, mas desta vez, tá muito difícil.

 

Alguém poderia me ajudar?

 

Estrutura da tabela.

 

Tabela: compras

campos: loja, login, mes, ano, parceiro, documento, nota_fiscal, valor, bonificacoes_porcentagem, bonificacoes_valores.

 

Os campos utilizados para o gráfico seria, o campo parceiro, que filtra o campo loja, que mostra valores do do campo valor + bonificacoes_porcentagem = bonificacoes_valores, então as barras teria que pegar como base de contagem o campos bonificacoes_valores.

 

Se alguém poder me ajudar seria imensamente grato.

 

Sds,

 

Vagner Nunes

Compartilhar este post


Link para o post
Compartilhar em outros sites

tipo esse grafico abaixo, só mude o

 

'---------------------Valores-----------------
Dim Title(12) 'Pair title
Title(1) = "Jan"
Title(2) = "Feb"
Title(3) = "Mar"
Title(4) = "Apr"
Title(5) = "May"
Title(6) = "Jun"
Title(7) = "Jul"
Title(8) = "Aug"
Title(9) = "Sep"
Title(10) = "Oct"
Title(11) = "Nov"
Title(12) = "Dec"

Dim StackTitle(3) 
StackTitle(1) = "Novo"
StackTitle(2) = "Cancelado"
StackTitle(3) = "Frozen"

Dim i(12, 3) 'i(Bar#, Stack) (1-New, 2-Cancelled, 3-Frozen)
Dim Values(12, 3)
i(1, 1) = 0
i(1, 2) = 2
i(1, 3) = 5
i(2, 1) = 3
i(2, 2) = 0
i(2, 3) = 1
i(3, 1) = 2
i(3, 2) = 0
i(3, 3) = 0
i(4, 1) = 1
i(4, 2) = 0
i(4, 3) = 0
i(5, 1) = 3
i(5, 2) = 0
i(5, 3) = 0
i(6, 1) = 6
i(6, 2) = 4
i(6, 3) = 0
i(7, 1) = 14
i(7, 2) = 1
i(7, 3) = 0
i(8, 1) = 8
i(8, 2) = 1
i(8, 3) = 4
i(9, 1) = 8
i(9, 2) = 1
i(9, 3) = 2
i(10, 1) = 7
i(10, 2) = 21
i(10, 3) = 16
i(11, 1) = 14
i(11, 2) = 5
i(11, 3) = 25
i(12, 1) = 6
i(12, 2) = 2
i(12, 3) = 11

Maxvalue = 50
TopPadding = 20
SidePadding = 200
BarPadding = 39
Barwidth = 23
LineLengths = 70

abaixo doce completo:

 

<%

'---------------------Valores-----------------
Dim Title(12) 'title
Title(1) = "Jan"
Title(2) = "Feb"
Title(3) = "Mar"
Title(4) = "Apr"
Title(5) = "May"
Title(6) = "Jun"
Title(7) = "Jul"
Title(8) = "Aug"
Title(9) = "Sep"
Title(10) = "Oct"
Title(11) = "Nov"
Title(12) = "Dec"

Dim StackTitle(3) 
StackTitle(1) = "Nooc"
StackTitle(2) = "Cancelado"
StackTitle(3) = "Frozen"

Dim i(12, 3) 'i(Bar#, Stack) (1-New, 2-Cancelled, 3-Frozen)
Dim Values(12, 3)
i(1, 1) = 0
i(1, 2) = 2
i(1, 3) = 5
i(2, 1) = 3
i(2, 2) = 0
i(2, 3) = 1
i(3, 1) = 2
i(3, 2) = 0
i(3, 3) = 0
i(4, 1) = 1
i(4, 2) = 0
i(4, 3) = 0
i(5, 1) = 3
i(5, 2) = 0
i(5, 3) = 0
i(6, 1) = 6
i(6, 2) = 4
i(6, 3) = 0
i(7, 1) = 14
i(7, 2) = 1
i(7, 3) = 0
i(8, 1) = 8
i(8, 2) = 1
i(8, 3) = 4
i(9, 1) = 8
i(9, 2) = 1
i(9, 3) = 2
i(10, 1) = 7
i(10, 2) = 21
i(10, 3) = 16
i(11, 1) = 14
i(11, 2) = 5
i(11, 3) = 25
i(12, 1) = 6
i(12, 2) = 2
i(12, 3) = 11

Maxvalue = 50
TopPadding = 20
SidePadding = 200
BarPadding = 39
Barwidth = 23
LineLengths = 70
'---------Advanced-----------------------------

NumBars = 12 'Must be the same as or lower than i(x, 3)
	     'Must be the same as or lower than Title(x)
	     'Must assign values

NumStacks = 3  'Must be the same as or lower than i(6, x) 
	     'Must have color(from 1 to numbars).gif
	     'Must assign values

%>






















<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
.Bargraph {
	position:absolute;
	top:0px;
	left:0px;
	z-index:2;
	visibility:hidden;
	font: 10pt MS Comic Sans,arial,sans-serif;
	}
-->
</STYLE>

</HEAD>
<BODY>







<%
Dim x
Dim r
Dim s
Dim t 'Counter Variables

Dim step 'Stack height

for x = 1 to numbars
for r = 1 to numstacks
values(x, r) = i(x, r)
i(x, r) = ((i(x, r) / Maxvalue) * 400)
next
next
%>

<%
t = 0
PosLeft = SidePadding + 30
for x = 1 to numbars
for r = 1 to numstacks
t = t + 1 
	Step = 0
	If r > 1 then
		For s = 1 to (r-1)
			Step = Step + i(x, s)
		Next
	End If

if i(x, r) <> 0 then
%>
<DIV CLASS=Bargraph ID=bg<%=t%>>
<%if r = 1 then%>
<img src="color<%=r%>.gif" Alt=<%=Title(x)%> Height=<%=(i(x, r) + 3)%> Width=<%=Barwidth%> border="1" style="border-style: solid; border-color: #0000FF" class="bar" id=section<%=r%>>
<%else%>
<img src="color<%=r%>.gif" Alt=<%=Title(x)%> Height=<%=(i(x, r) + 4)%> Width=<%=Barwidth%> border="1" style="border-style: solid; border-color: #0000FF" class="bar" id=section<%=r%>>
<%end if%>
</DIV>


<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['bg<%=t%>']");
		BarGraphOBJ.style.posLeft = (<%=PosLeft%>);
		BarGraphOBJ.style.posTop = (<%=(400 - i(x, r) + TopPadding) - Step%>);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>







<%
end if

If r = 1 then 
	t = t + 1
%>

	<DIV CLASS=Bargraph ID=Title<%=t%> >
	<%=Title(x)%>
	</DIV>
<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['Title<%=t%>']");
		BarGraphOBJ.style.posLeft = (<%=PosLeft%>);
		BarGraphOBJ.style.posTop = (400 + 10 + <%=TopPadding%>);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>
<% 
End If
	Next
PosLeft = PosLeft + BarPadding
Next
%>

<DIV CLASS=Bargraph ID=line1>
<img src="line.gif" width=<%=numbars * barpadding + 90%> height=2> 
</DIV>
<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['line1']");
		BarGraphOBJ.style.posLeft = (<%=Sidepadding - 65%>);
		BarGraphOBJ.style.posTop = (400 + <%=TopPadding%> - 7);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>

<%for x = 1 to Numstacks%>
<DIV CLASS=Bargraph ID=legendline<%=x%>>
<img src="color<%=x%>.gif" width=<%=numbars * barpadding + 90%> height=2> 
</DIV>
<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['legendline<%=x%>']");
		BarGraphOBJ.style.posLeft = (<%=Sidepadding - 65%>);
		BarGraphOBJ.style.posTop = (400 + <%=TopPadding%> - 7 + <%=x%> * 23);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>

<DIV CLASS=Bargraph ID=legend<%=x%>>
<table width=<%=104 + numbars * (barpadding)%>>
<tr>
<td width = 104>
<img src="color<%=x%>.gif" width=10 height=10> <Font size=2><%=stacktitle(x)%></font>
</td>

<%for r = 1 to NumBars%>
	<td width = <%=barpadding%> valign=top>
	<%=values(r, x)%>
	</td>
<%next%> 

</tr>
</table>
</DIV>
<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['legend<%=x%>']");
		BarGraphOBJ.style.posLeft = (<%=Sidepadding - 70%>);
		BarGraphOBJ.style.posTop = (400 + <%=TopPadding%> + 25 * <%=x%>);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>
<%next%>

<DIV CLASS=Bargraph ID=line2>
<img src="line.gif" width=2 height=<%=400 * 1.07 + numstacks * 23%>> 
</DIV>
<script LANGUAGE="javascript">
		var BarGraphOBJ = eval("document.all['line2']");
		BarGraphOBJ.style.posLeft = (<%=(SidePadding + 24 + (numbars * barpadding))%>);
		BarGraphOBJ.style.posTop = (<%=TopPadding%>);
		BarGraphOBJ.style.visibility = "visible";
</SCRIPT>
</BODY>
</HTML>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.