我也不懂,这是其它人给我贴的,好象应该对你有帮助。
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>将图表数据源绑定到电子表格</TITLE>
</HEAD>
<BODY style="font-size:9pt;">
<b>下面的电子表格数据可在客户端修改
<br>
修改后相应的图表可自动更新</b>
<br>
<!-- Spreadsheet Control -->
<OBJECT id=Spreadsheet1
classid="clsid:0002E510-0000-0000-C000-000000000046" >
</OBJECT>
<!-- Chart Control -->
<p>
<object classid="clsid:0002E500-0000-0000-C000-000000000046"
id="ChartSpace1"
style="HEIGHT: 300; WIDTH: 350">
</object>
<object classid="clsid:0002E500-0000-0000-C000-000000000046"
id="ChartSpace2"
style="HEIGHT: 300; WIDTH: 400">
</object>
<!-- Script for loading the chart -->
<script language=VBScript>
Sub Window_onLoad()
CreateSheet(Spreadsheet1)
BindChartToSpreadsheet Chartspace1, Spreadsheet1, _
"a2:a4", "b1:c1", "b2:c4",False
BindChartToSpreadsheet Chartspace2, Spreadsheet1, _
"b1:c1", "a2:a4", "b2:c4",True
End Sub
'创建电子表格
Sub CreateSheet(cspace)
dim ch(25),months,sales
for i=0 to 25
ch(i)=chr(asc("A")+i)
next
months=array("","一月份","二月份")
sales=array("北京",30000,32000,"上海",34000,40000,"广州",40000,45000)
dim cols,rows,col,row
cols=LenOfArray(months)
rows=LenOfArray(sales)/LenOfArray(months)+1
cspace.ScreenUpdating=False
cspace.ActiveSheet.Protection.Enabled=False
cspace.AutoFit=True
cspace.DisplayColHeaders=False
cspace.DisplayRowHeaders=False
cspace.DisplayToolbar=False
cspace.TitleBar.Caption="各城市销售情况"
for row=1 to rows
for col=1 to cols
if row=1 then
cspace.Cells(row,col).value=months(col-1)
else
cspace.Cells(row,col).value=sales((row-2)*cols+col-1)
if col<>1 then
cspace.Cells(row,col).NumberFormat="$#,##0"
cspace.Cells(row,col).Locked=False
end if
end if
next
next
cspace.ViewableRange="A1:"&ch(cols-1)&rows
cspace.ActiveSheet.Protection.Enabled=True
cspace.ScreenUpdating=True
End Sub
'返回数组长度
Function LenOfArray(objArray)
if not isArray(objArray) then
LenOfArray=0
exit function
end if
LenOfArray=UBound(objArray)-Lbound(objArray)+1
End Function
'将图表数据源绑定到电子表格
Sub BindChartToSpreadsheet(cspace, sheet, srngSeries, srngCategories, _
srngValues, fSeriesInCols)
Dim cht
Dim ser
Dim rngValues
set c = cspace.Constants
cspace.Clear
'绑定数据源
set cspace.DataSource = sheet
set cht = cspace.Charts.Add()
cht.HasLegend = True
cht.SetData c.chDimSeriesNames, 0, srngSeries
cht.SetData c.chDimCategories, 0, srngCategories
set rngValues = sheet.Range(srngValues)
for each ser in cht.SeriesCollection
if fSeriesInCols then
ser.SetData c.chDimValues, 0, _
rngValues.Columns(ser.Index + 1).Address
else
ser.SetData c.chDimValues, 0, _
rngValues.Rows(ser.Index + 1).Address
end if
set dl=ser.DataLabelsCollection.Add()
dl.Font.Size = 9
dl.Font.Color = "red"
dl.Position = c.chLabelPositionTop
next
FormatChart c,cht
End Sub
'设置图表显示字体及数据轴格式
Sub FormatChart(c,cht)
cht.Legend.Font.size=9
set ax = cht.Axes(c.chAxisPositionBottom)
ax.Font.Size = 9
set ax = cht.Axes(c.chAxisPositionLeft)
ax.Font.Size = 9
ax.NumberFormat = "$#,##0"
End Sub
</script>
<%
Window_onLoad
%>
</body>
</html>