Dim obj
Set obj = createObject("ChinaaspChart.pie")
obj.AddValue "男", 150
obj.AddValue "女", 45
obj.AddValue "不知道", 15
obj.ChartName = "性别比例图"
obj.FileName = "d:\123.gif"
obj.SaveChart
除了在vb里面可以调用,这段代码同样也可以在asp里面调用。
下面请follow me 编写我们的组件。
1.New project , 请选择activex dll,在project explorer面板上选择project1,然后在属性面板上修改其name为ChinaASPChart。同样把里面的class modules修改为pie
2.保存该project,将project存为chinaaspchart.vbp,将class1.cls存为pie.cls。
3.菜单project,选择菜单项References,然后请把Microsoft Active Server Pages Ojbect Library、Microsoft Excel 9.0 Object Library、COM+ Services Type Library选上。
注意:在NT4/win98上没有COM+ Service Type Library这个东东,应该选Microsoft Transaction Server Type Library
4.编辑pie.cls,代码如下:
Dim xl
Dim m_chartName
Dim m_chartData()
Dim m_chartType
Dim m_fileName
Public ErrMsg
Public foundErr
Dim iCount
Type m_Value
label As String
value As Double
End Type
Dim tValue As m_Value
Public Property Let ChartType(ChartType)
m_chartType = ChartType
End Property
Public Property Get ChartType()
ChartType = m_chartType
End Property
Public Property Let ChartName(ChartName)
m_chartName = ChartName
End Property
Public Property Get ChartName()
ChartName = m_chartName
End Property
Public Property Let FileName(fname)
m_fileName = fname
End Property
Public Property Get FileName()
FileName = m_fileName
End Property
Public Sub AddValue(label, value)
iCount = iCount + 1
ReDim Preserve m_chartData(iCount)
tValue.label = label
tValue.value = value
m_chartData(iCount) = tValue
End Sub
Public Sub SaveChart()
On Error Resume Next
Dim iSheet
Dim i
Set xl = New Excel.Application
xl.Application.Workbooks.Add
xl.Workbooks(1).Worksheets("sheet1").Activate
If Err.Number <> 0 Then
foundErr = True
ErrMsg = Err.Description
Err.Clear
Else
xl.Workbooks(1).Worksheets("sheet1").Cells("2,1").value = m_chartName
For i = 1 To i