Código PHP:
<%
'this is to be included within a page to draw out pie graphs
'****************************************************************************************************************************
'
' Author: Mark Baekdal 23 September 2002
'
' DrawPieGraph
'
' Funnily enough DrawPieGraph does just that. It draws a Pie graph.
'
' 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.
'
'****************************************************************************************************************************
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