Foros del Web » Programando para Internet » ASP Clásico »

clase para graficos de pastel buenisimo

Estas en el tema de clase para graficos de pastel buenisimo en el foro de ASP Clásico en Foros del Web. hola baje un codigo al parecer muy bueno que dibuja graficas de pastel para estadisticas y reportes, el problema es que no se como usarlo ...
  #1 (permalink)  
Antiguo 05/02/2005, 22:48
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 22 años, 5 meses
Puntos: 4
De acuerdo clase para graficos de pastel buenisimo

hola baje un codigo al parecer muy bueno que dibuja graficas de pastel para estadisticas y reportes, el problema es que no se como usarlo asi k lo dejo aqui para k lo prueben y por favor me expliquen como usarlo porqk la verdad no lo logro hacerlo,
gracias... espero les sirva a todos tambien.


Código:
 
<%
class DrawPieGraph
 private pvDiameter
 private pvShadow
 private pvTitle
 private rsPieGraphValues
 private pvShowLegend
 private pvLegendSize
 private pvHTMLinnerTableDef
 private pvHTMLouterTableDef
 private pvShowValues
 private pvFormatValuesAsCurrency
 private pvFontDef
 '-----------
 private function ReturnRecordset
  dim rs
  set rs = CreateObject("ADODB.Recordset")
  'value fld is currency data type (6)
  rs.Fields.append "value",6
  'label fld is varchar type (200), length is 50 chars long max
  rs.Fields.append "label",200,50
  'color fld is varchar type (200), length is 20 chars long, must be hex value
  rs.Fields.append "color",200,20
  'open the rs ready for adding records
  rs.Open 
  set ReturnRecordset = rs
 end function
 '----------
 private function ReturnValueWithFontTags(value)
  ReturnValueWithFontTags = pvFontDef & value & "</font>"
 end function
 '----------
 private sub Class_Initialize
  set rsPieGraphValues = ReturnRecordset
  pvDiameter = 100
  pvShadow = true
  pvTitle = ""
  pvShowLegend = true
  pvLegendSize = 20
  pvHTMLinnertableDef = "<table cols=""2"" border=1>"
  pvHTMLouterTableDef = "<table cellpadding=""12"" style=""border: 2px outset;"">"
  pvShowValues = true
  pvFormatValuesAsCurrency = false
  pvFontDef = "<font size=2>"
 end sub
 '----
 'the diameter of the circle, integer
 public property let Diameter(value)
  pvDiameter=cint(value)
 end property
 '------------
 public property get Diameter
  Diameter=pvDiameter
 end property
 '------------
 'the shadow true/false
 public property let Shadow(value)
  pvShadow=cbool(value)
 end property
 '-----------
 public property get Shadow
  Shadow=pvShadow
 end property
 '------------
 'the title - string value
 public property let Title(value)
  pvTitle=cstr(value)
 end property
 '---------------
 public property get Title
  Title=pvTitle
 end property
 '------------
 'draw out the legend
 public property let ShowLegend(value)
  pvShowLegend=cbool(value)
 end property
 '-----------
 public property get ShowLegend
  ShowLegend=pvShowLegend
 end property
 '---------
 'the legend size
 public property let LegendSize(value)
  pvLegendSize=cstr(value)
 end property
 '----------
 public property get LegendSize
  LegendSize=pvLegendSize
 end property
 '---------
 'table definition for inner table to allow customisation
 public property let HTMLinnerTableDef(value)
  pvHTMLinnertableDef=cstr(value)
 end property
 '----------
 public property get HTMLinnerTableDef
  HTMLinnerTableDef=pvHTMLinnertableDef
 end property
 '--------
 'table definition for inner table to allow customisation
 public property let HTMLouterTableDef(value)
  pvHTMLouterTableDef=cstr(value)
 end property
 '----------
 public property get HTMLouterTableDef
  HTMLouterTableDef=pvHTMLouterTableDef
 end property
 '-----------
 'show the values or not
 public property let ShowValues(value)
  pvShowValues=cbool(value)
 end property
 '--------------
 public property get ShowValues
  ShowValues=pvShowValues
 end property
 '-----------
 'the size of the font for the value display
 public property let FontDef(value)
  pvFontDef=cstr(value)
 end property
 '-----------
 public property get FontDef
  FontDef=pvFontDef
 end property
 '------------
 'format the values as currency or not
 public property let FormatValuesAsCurrency(value)
  pvFormatValuesAsCurrency=cbool(value)
 end property
 '-------
 public property get FormatValuesAsCurrency
  FormatValuesAsCurrency=pvFormatValuesAsCurrency
 end property
 '----------
 'add the values for the different segments of the pie chart
 public sub AddValue(value,label,color)
  with rsPieGraphValues
   .AddNew
   .Fields("value") = value
   .Fields("label") = label
   .Fields("color") = color
   .Update  
  end with
 end sub
 '--------------
 public sub DeleteAllAddedValues
  set rsPieGraphValues = nothing
  set rsPieGraphValues = ReturnRecordset
 end sub
 '-------------
 'draw the actual graph
 public sub Draw
  Dim startPoint, endPoint, sumOfValues, percentage, i
  Dim strTitle, magicNumber
  dim Height, Width
  if rsPieGraphValues.EOF and rsPieGraphValues.BOF then exit sub
  magicNumber = 23592960 ' It's mystical, magical, kinda nutty even
  startPoint = 5850000 ' this setting is approximately 12:00 noon
  strTitle=pvTitle
  
  'height to width ratio is h:w = 0.75:1
  'we work out the height and width from the diameter given
  'the formula is diameter=100 therefore height=375pt; width=500pt
  Height = round(pvDiameter * 3.75,0)
  Width  = round(pvDiameter * 5,0)
  with response
  ' GET SUM OF VALUES ***
  rsPieGraphValues.MoveFirst 
  do while not rsPieGraphValues.EOF 
   sumOfValues = sumOfValues + rsPieGraphValues("value").Value 
   rsPieGraphValues.MoveNext 
  loop
  if sumOfValues=0 then exit sub
  ' VML tags *****
  .Write "<xml:namespace prefix=""v""/>"
  .Write "<object id=""VMLRender"" classid=""CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E"" width=""0"" height=""0""></object>"
  .Write "<style> v\:* {behavior=url(#VMLRender)}</style>"
  ' *********
  ' Start Outer Table //
  .Write pvHTMLouterTableDef & vbCrLf 
  .Write "<tr>" & vbCrLf 
  .Write "<td>" & vbCrLf 
  ' ********
  ' Start Inner Table //
  .Write pvHTMLinnertableDef & vbCrLf
  if pvTitle<>"" then
   .Write "<tr align=""center"" >" & vbCrLf
   ' Create Title //
   if pvShowLegend then
	.Write "<td colspan=""2""><b>" & strTitle & "</b><br><br></td>" & vbCrLf
   else
	.Write "<td><b>" & strTitle & "</b><br><br></td>" & vbCrLf
   end if
   .Write "</tr>" & vbCrLf
  end if
  ' *** Start Building Pie //
  .Write "<tr>" & vbCrLf
  .Write "<td>" & vbCrLf
  'VML tags
  .Write "<div style=""margin-top=0pt"">" & vbCrLf
  .Write "<v:group style=""height=" & Height & "pt; width=" & Width & "pt"" coordsize=""4320,3240"">" & vbCrLf
  ' BUILD THE SHADOW 
  if pvShadow then
   .Write("<v:shape style='position:relative; width:4320; height:3240' fillcolor=#C0C0C0 path=""M 790 760 AE 790 760 707 707 " & startPoint & " " & magicNumber & " X E"">" & vbCrLf)
   .Write("<v:stroke on=""False""/>" & vbCrLf)
   .Write("</v:shape>" & vbCrLf)
  end if
  ' BUILD THE PIE
  rsPieGraphValues.MoveFirst 
  do while not rsPieGraphValues.EOF 
   percentage = FormatNumber(rsPieGraphValues("value").Value / sumOfValues, 3)
   endPoint = magicNumber * percentage
   endPoint = FormatNumber(endPoint, 0)
   endPoint = Fix(endPoint)
   .Write("<v:shape style='width:4320; height:3240' strokeweight=0.5pt fillcolor=" & rsPieGraphValues("color").Value & " path=""M 750 720 AE 750 720 707 707 " & startPoint & " " & endPoint & " X E""/>" & vbCrLf)
   startPoint = startPoint + endPoint
   rsPieGraphValues.MoveNext 
  loop
  ' VML tag
  .Write("</v:group></div>" & vbCrLf)
  .Write("</td>" & vbCrLf)
  ' End Build Pie 
  ' Start Legend Table 
  if pvShowLegend then
   .Write("<td>" & vbCrLf)
   .Write("<table bordercolor=""white"" border=""1"" cellpadding=""2"">" & vbCrLf)
   ' Step 6) BUILD THE LEGEND
   rsPieGraphValues.MoveFirst 
   do while not rsPieGraphValues.EOF 
	.Write("<tr>" & vbCrLf)
	' Color //
	.Write "<td><img src='../images/1pixel.gif' border=1 width='" & pvLegendSize & "' height='" & pvLegendSize & "' style='background:" & rsPieGraphValues("color").Value & ";'/></td>"
	' Category //
	.Write("<td width=""75"">" & vbCrLf)
	.Write ReturnValueWithFontTags(rsPieGraphValues("label").Value) & vbCrLf
	.Write("</td>" & vbCrLf)
	' Value or Percent //
	if pvShowValues then
	 .Write("<td align=""right"">" & vbCrLf)
	 if pvFormatValuesAsCurrency then
	  .Write ReturnValueWithFontTags(formatnumber(rsPieGraphValues("value").Value,2,true,false,false)) & vbCrLf
	 else
	  .Write ReturnValueWithFontTags(rsPieGraphValues("value").Value) & vbCrLf
	 end if
	 .Write("</td>" & vbCrLf)
	end if
	.Write("</tr>" & vbCrLf)
	rsPieGraphValues.MoveNext 
   loop
	
   ' End Legend Table 
	  .Write("</table>" & vbCrLf)
   .Write("</td>" & vbCrLf)
  end if
 
  ' End Inner Table 
  .Write("</tr>" & vbCrLf)
  .Write("</table>" & vbCrLf)
 
  ' End Outer Table 
  .Write("</td>" & vbCrLf)
  .Write("</tr>" & vbCrlf)
  .Write("</table>" & vbCrLf)
  end with
 end sub
end class 
%>
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #2 (permalink)  
Antiguo 05/02/2005, 22:49
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 22 años, 5 meses
Puntos: 4
aqui coloco los comentarios que traia por si sirven de algo, ademas del autor

Código:
 'this is to be included within a page to draw out pie graphs
' 
' Author:  Mark Baekdal 23 September 2002
' DrawPieGraph
' Public Properties:  Please note that all properties are set defaults when the class is initialized.
' Diameter	 read/write int
' Diameter is not strictly the diameter of the circle increasing this exponatially increases the
' size of the circle.
'Shadow	  read/write boolean
'  Draws a nice little shadow with your pie.
'Title read/write string
' Set this to title your graph. You can also include html formating if desired. ie: <font size=5>
'ShowLegend	 read/write boolean
' Set this to false if you don't want to display the legend.
' LegendSize	 read/write int
' This sets the size of the images used for the legend. Personally I like 10.
' HTMLinnerTableDef   read/write string
' Set this to change the display of the graph.
' HTMLouterTableDef   read/write string
' Set this to change the display of the graph.
'ShowValues	 read/write boolean
'   Set this to false if you don't want to display the values.
' FormatValuesAsCurrency  read/write boolean
' Set this to format the value as n.nn
' FontDef	  read/write string
'   Set this to change the display of the legend characters.
' Public Methods:
'  AddValue	
'  Parameters
'value: the value which will be converted to a percentage of the overall total
' to display a segment of the pie graph.
'  label: a title/description of the value.
'color: the color to use for this segment. Must be in hex format ie:#00ffdd etc
' call AddValue for all the different segments that you want to display.
' DeleteAllAddedValues
' Parameters none
'  call DeleteAllAddedValues to delete all the values previously added. This is useful if you
'are drawing multiple pie graphs, so you can use the one object to do them all. 
' Draw
'	Parameters none
' call Draw to draw out the graph.
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #3 (permalink)  
Antiguo 06/02/2005, 10:24
Avatar de Muzztein  
Fecha de Ingreso: agosto-2002
Ubicación: Hangar 18
Mensajes: 1.703
Antigüedad: 21 años, 9 meses
Puntos: 16
colocalo en la biblioteca pues
  #4 (permalink)  
Antiguo 06/02/2005, 10:48
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 22 años, 5 meses
Puntos: 4
pero antes de colocarla en la biblioteca seria bueno saber como funciona.. ni siquiera se como se hace el llamado.. ojala alguien nos expliqeu porqeu al parecer es excelente para hacer graficos de torta. pie chart.
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #5 (permalink)  
Antiguo 07/02/2005, 11:34
Avatar de akela  
Fecha de Ingreso: septiembre-2000
Ubicación: Frente a la compu
Mensajes: 660
Antigüedad: 23 años, 9 meses
Puntos: 2
Pues según dice ahí llama a Drawpara dibujar la gráfica
  #6 (permalink)  
Antiguo 07/02/2005, 14:48
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 22 años, 5 meses
Puntos: 4
si pero con que parametros, ya la he probado como dices y no funciona..

por favor alguien que la pruebe y nos diga como funciona.. asi podremos hacer pruebas..
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #7 (permalink)  
Antiguo 07/02/2005, 19:36
Avatar de akela  
Fecha de Ingreso: septiembre-2000
Ubicación: Frente a la compu
Mensajes: 660
Antigüedad: 23 años, 9 meses
Puntos: 2
que te marca, al llamarla solo como DRAW me da un error "no coinciden los tipos"

al seguir leyendo la documentaciòn dece que draw no usa parámetros.
  #8 (permalink)  
Antiguo 07/02/2005, 20:20
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 22 años, 5 meses
Puntos: 4
exacto es el mismo error qeu me saca ami. pero es porque no es asi de simple como llamar a draw y ya, ni siquiera le hemos especificado los valores para que dibuje el pastel entonces.... no sacara nada. hay varias clases qeu hacen eso creo qeu hay una qeu nos conecta con la bd para qeu coloquemos los datos, el color y el valor para cada pedazo del pastel.. esperemos que alguien pueda darnos una ayuida para tener este script funcionando pronto..
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #9 (permalink)  
Antiguo 08/02/2005, 12:23
Avatar de akela  
Fecha de Ingreso: septiembre-2000
Ubicación: Frente a la compu
Mensajes: 660
Antigüedad: 23 años, 9 meses
Puntos: 2
Pues lo que segùn entiendo:

Public Methods:
AddValue <- función
Parameters
value: the value which will be converted to a
percentage of the overall total to display a segment of the pie graph.
Valor: El valor que será convertido a porcentaje del total que corresponde a un segmento del pastel.
label: a title/description of the value.
Etiqueta:Un titulo/descripcion de el valor
color: the color to use for this segment. Must be in hex format ie:#00ffdd etc
Color: El color a usar para este segmento. Debe ser en Formáto Hex. PE. #00ffdd

call AddValue for all the different segments that you want to display.
llama AddValue para todos los diferentes segmentos que quieras desplegar

DeleteAllAddedValues <- función
Parameters none
Parametros ninguno

call DeleteAllAddedValues to delete all the values previously added. This is useful if you are drawing multiple pie graphs, so you can use the one object to do them all.

llama DeleteAllAddedValues para borrar todos los valores anterirormente agregados. Esto es muy útil para ti si estás dibujando multeples gráficas de pastel, asi que puedes usar este objeto para liberar los datos.



Draw
Parameters none

Draw parametros ninguno

call Draw to draw out the graph.


Por lo que enetendí

ya he probado de todas las maneras llamar antes de dibujar a la función:

AddValue pero siempre me tira un error, no se si paso los parámetros de forma correcta:

He intentado:

AddValue(10,"etiqueta",#00FFDD)
AddValue(.10, "etiqueta", #00FFDD)
AddValue(10,etiqueta,"#00FFDD")

y varios más

haz encontrado algo nuevo Lexus?

Última edición por akela; 08/02/2005 a las 12:33
  #10 (permalink)  
Antiguo 10/02/2005, 09:32
Avatar de akela  
Fecha de Ingreso: septiembre-2000
Ubicación: Frente a la compu
Mensajes: 660
Antigüedad: 23 años, 9 meses
Puntos: 2
No consigo hacerla andar , de donde la baajste¿?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:33.