以下代碼存成asp文件:

<%
Dim?strPicFile'生成的臨時圖表圖片名
strPicFile=server.MapPath(".")&"\tmpchart.gif"
''圖表數據部分,可以從數據庫中取得
sdata1="45,75,78,67,45,75,78,80"
sdata2
="36,56,23,73"
x_line
="1,2,3,4"
a_group
="A,B"
a_group_arr?
=?split(a_group,",")?
x_line_arr?
=?split(x_line,",")
data1_arr?
=?split(Sdata1,",")?
data2_arr?
=?split(Sdata2,",")

''-----------------生成圖表開始---------------------------------------------------
Set?ChartTmp?=?CreateObject("OWC10.ChartSpace")
Set?cc?=?ChartTmp.Constants?''返回一個對象,此對象允許腳本用戶使用已命名的常量。
'
ChartTmp.Charts.delete(0)
Set?cht?=?ChartTmp.Charts.Add(0)?''添加一個圖表對象
cht.Type=cc.chChartTypeColumnClustered'?
'
'設置圖表工作區中包含標題
ChartTmp.HasChartSpaceTitle?=?true?
with?ChartTmp.ChartSpaceTitle
??.Caption?
="測試圖表"''設置圖表工作區標題內容?
??''有關字體的設置?
??.Font.Bold?=?True?''設置圖表工作區標題內容是否粗體?
??.Font.Name?=?"Times?New?Roman"?''設置圖表工作區標題內容的字體?
??.Font.Size?=?18?''設置圖表工作區標題內容的大小(單位:磅)?
end?with
''-------設置圖例--------------------------------------------?
cht.HasLegend?=?True?''指定圖表工作區中含有圖例?
cht.Legend.Font.Size?=?9?''其他有關字體項的設置參見設置圖表標題部分?
cht.Legend.Position?=?cc.chLegendPositionBottom?''設置圖例對其方式
'
'-------添加數據系列1(柱狀圖)--------------------------------------------?
Set?Series0?=?cht.SeriesCollection.Add()?''添加一個數據系列?
with?Series0
?
'?.Type=cc.chChartTypeColumnClustered'?(省略同圖表基本類型)
?.SetData?cc.chDimSeriesNames,?cc.chDataLiteral,?a_group_arr(0)?''系列?
?.SetData?cc.chDimCategories,?cc.chDataLiteral,?x_line_arr?''橫(X)軸數據(分類軸)?
?.SetData?cc.chDimValues,?cc.chDataLiteral,?data1_arr''''縱(Y)軸數據
end?with
Set?dl?=?Series0.DataLabelsCollection.Add?''添加圖例的數據標記?
dl.HasValue?=?True'顯示數值
'
'-------添加數據系列2(柱狀圖)--------------------------------------------?
Set?Series0?=?cht.SeriesCollection.Add()?''添加一個數據系列?
with?Series0
?
'?.Type=cc.chChartTypeColumnClustered'?(省略同圖表基本類型)
?.SetData?cc.chDimSeriesNames,?cc.chDataLiteral,?a_group_arr(1)''系列?
?.SetData?cc.chDimCategories,?cc.chDataLiteral,?x_line_arr?''橫(X)軸數據(分類軸)?
?.SetData?cc.chDimValues,?cc.chDataLiteral,?data2_arr''''縱(Y)軸數據
end?with
Set?dl?=?Series0.DataLabelsCollection.Add?''添加圖例的數據標記?
dl.HasValue?=?True
''-------添加數據系列1(折線圖)------------------------------------------?
Set?Series0?=?cht.SeriesCollection.Add()?''添加一個數據系列
with?Series0
?.Type
=cc.chChartTypeLineMarkers'(折線圖)
?.setData?cc.chDimSeriesNames,?cc.chDataLiteral,?a_group_arr(0)''系列?
?.SetData?cc.chDimCategories,?cc.chDataLiteral,?x_line_arr?''橫(X)軸數據(分類軸)?
?.SetData?cc.chDimValues,?cc.chDataLiteral,?data1_arr''''縱(Y)軸數據
end?with??
''-------添加數據系列2(折線圖)------------------------------------------?
Set?Series0?=?cht.SeriesCollection.Add()?''添加一個?
with?Series0
?.Type
=cc.chChartTypeLineMarkers'(折線圖)
?.setData?cc.chDimSeriesNames,?cc.chDataLiteral,?a_group_arr(1)''系列?
?.SetData?cc.chDimCategories,?cc.chDataLiteral,?x_line_arr?''橫(X)軸數據(分類軸)?
?.SetData?cc.chDimValues,?cc.chDataLiteral,?data2_arr''''縱(Y)軸數據
end?with
??
Set?dl?=?Series0.DataLabelsCollection.Add?''添加圖例的數據標記?
??dl.HasValue?=?true'顯示數值
??dl.HasPercentage?=?true'顯示百分比

'導出圖片
ChartTmp.ExportPicture?strPicFile,?"GIF",?760,?350

Set?ChartTmp?=?Nothing
''生成圖表結束
%>

<img?src=tmpchart.gif>

附:常見圖表類型參考

chChartTypeColumnClustered 柱狀圖
chChartTypeBarClustered 條形圖
chChartTypePie 餅圖
chChartTypeArea 面積圖
chChartTypeRadarLine 雷達線圖
chChartTypeSmoothLine 平滑曲線圖
chChartTypeDoughnut 環形圖