台灣最大程式設計社群網站
線上人數
1139
 
會員總數:246101
討論主題:189673
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> 圖表製作方式(長條圖,圓餅圖)
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
圖表製作方式(長條圖,圓餅圖)
價值 : 0 QP  點閱數:794 回應數:0
樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員
使用方法:
1.下列共7個檔案,請將檔案存放於graphic目錄中
2.其中datasource.txt,graphicsetup1.txt,graphicsetup2.txt,graphicsetup3.txt不可修改
3.graphic0.txt是長條圖檔案不可修改
我隨後會將其他圖形檔案貼上,此時只需將執行檔graphic.asp中行列6 iechart1="graphic0"修改即可顯示不同圖形
exp : graphic0.txt長條圖 iechart1="graphic0"
graphic2.txt圓形圖 iechart1="graphic2" 依此類推
4.testdata.txt為圖表資料來源檔案
5.graphic.asp為執行檔
6.另一檔案為iechart.cab,可至微軟網站下載

執行檔:graphic.asp
<% servername="http://"&request.servervariables("server_name")&"/graphic/"
'圖表資料來源
filename="testdata.txt"

'長條圖代稱 (Column Clustered)
iechart1="graphic0"

'顯示圖表長度和高度
grpwidth=500
grpheight=300

'excel表長度和高度 (0是隱藏或更改 tablewidth & tableheight 數值可顯示 excel表)
tablewidth=0
tableheight=0

'excel表工作列 (0是隱藏 -1是顯示)
tableToolbar=0

'以下內容不要更動
graphiccomp=1
graphiccount=1
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set txtf = fs.OpenTextFile( Server.MapPath(filename) )
If Not txtf.atEndOfStream Then
datadetail = txtf.ReadAll
End If
Lines = Split( datadetail, vbCrLf )
For xx = 0 To 2
if xx<>0 then
compline=Server.HTMLEncode( Lines(xx) )
linesec = Split( compline, chr(9) )
For i = 0 To UBound(linesec)
if xx=1 and i=0 then
secno=clng(Server.HTMLEncode( Linesec(i) ))
elseif xx=2 and i=0 then
headno=clng(Server.HTMLEncode( Linesec(i) ))
end if
next
end if
next
chartstring=""
Set txtf = fs.OpenTextFile( Server.MapPath("graphicsetup3.txt") )
If Not txtf.atEndOfStream Then
setup3content = txtf.ReadAll
End If
chartstringx=""
for ggg=1 to graphiccount
for hhh=0 to 1
chartstringx=chartstringx&"<a:ElementExtension>"&vbCrLf
chartstringx=chartstringx&"<a:ElementID>"&"ChartSpace"&ggg&hhh&"</a:ElementID>"&vbCrLf
chartstringx=chartstringx&"<a:ConsumesRecordset/>"&vbCrLf
chartstringx=chartstringx&"<a:AlternateDataSource>"&"Spreadsheet"&ggg &"</a:AlternateDataSource>"&vbCrLf
chartstringx=chartstringx&"</a:ElementExtension>"&vbCrLf
next
next
setup3content =replace(setup3content,"chgraphic3",chartstringx)
chartstring=chartstring&vbCrLf&setup3content&vbCrLf

'產生圖表用Excel表
chartstringa=chartstring&"
<object classid='clsid:0002E510-0000-0000-C000-000000000046'
id='"&"Spreadsheet"&graphiccomp&"' codebase='"&servername&"iechart.cab'
width='"&tablewidth&"' height='"&tableheight &"'>"
Set txtf = fs.OpenTextFile( Server.MapPath("graphicsetup1.txt") )
If Not txtf.atEndOfStream Then
setup1content = txtf.ReadAll
End If
chartstringx=""
chartstringx=chartstringx&vbCrLf&setup1content&vbCrLf
chartstringx=chartstringx&"<table class=wcC34BB52 x:str>"
for xxx=0 to headno
if xxx=0 then
chartstringx=chartstringx&"
<col class=wcC34BB52 style='mso-width-source:userset'>"
else
chartstringx=chartstringx&"
<col class=wcC34BB52 style='mso-width-source:userset'>"
end if
next
Lines = Split( datadetail, vbCrLf )
For xx = 1 To secno+2
if xx<>1 then
compline=Server.HTMLEncode( Lines(xx) )
linesec = Split( compline, chr(9) )
For i = 0 To headno
session("menu"&i)=trim(Server.HTMLEncode( Linesec(i) ))
next
chartstringx=chartstringx&"<tr>"
for input=0 to headno
if xx=2 then
if input=0 then
chartstringx=chartstringx&"<td class=wcC34BB53></td>"
else
chartstringx=chartstringx&"
<td style='font-family: verdana, geneva, ms sans serif, arial;font-size: 9pt;'
align=center class=wcC34BB53 x:str='"&session("menu"&input)&"'></td>"
end if
else
if input=0 then
chartstringx=chartstringx&"
<td style='font-family: verdana, geneva, ms sans serif, arial;font-size: 9pt;'
class=wcC34BB52 x:str='"&session("menu"&input)&"'></td>"
else
chartstringx=chartstringx&"
<td style='font-family: verdana, geneva, ms sans serif, arial;font-size: 9pt;'
class=wcC34BB52 x:num='"&session("menu"&input)&"'></td>"
end if
end if
next
end if
chartstringx=chartstringx&"</tr>"
next
chartstringx=chartstringx&"</table>"

Set txtf = fs.OpenTextFile( Server.MapPath("graphicsetup2.txt") )
If Not txtf.atEndOfStream Then
setup2content = txtf.ReadAll
End If
setup2string=replace(setup2content,"chgtableToolbar",tableToolbar)
setup2mail=replace(setup2content,"chgtableToolbar","-1")
chartstringa=chartstringa&vbCrLf&chartstringx&vbCrLf&setup2string&vbCrLf
chartstringb=chartstringb&vbCrLf&chartstringx&vbCrLf&setup2mail&vbCrLf
chartstringa=chartstringa&"</object>"
chartstringb=chartstringb&"</object>"
response.write chartstringa
if showgrasize="" then
showgrasize="1.1"
end if
pos1=iechart1&".txt"
pos2="datasource.txt"
Set txtf = fs.OpenTextFile( Server.MapPath(pos1) )
If Not txtf.atEndOfStream Then
content = txtf.ReadAll
End If
Set txtf = fs.OpenTextFile( Server.MapPath(pos2) )
If Not txtf.atEndOfStream Then
datasource = txtf.ReadAll
End If
captionno=65
categoryno="A2:A"&secno+1
tempsource=""
for xxx=0 to headno-1
yyy=datasource
captionno=captionno+1
yyy=replace(yyy,"chgcaptino",chr(captionno)&"1")
yyy=replace(yyy,"chgindexno",xxx)
yyy=replace(yyy,"chgcategoryno",categoryno)
yyy=replace(yyy,"chgvalueno",chr(captionno)&"2:"&chr(captionno)&secno+1)
tempsource=tempsource&yyy&vbCrLf
next
coldatasource=tempsource
if iechart1="graphic7-1" or iechart1="graphic1-1" then
coldatasource=replace(coldatasource,"chgspreadno","10")
else
coldatasource=replace(coldatasource,"chgspreadno","0")
end if
colcontent=replace(content,"chgdatasource",coldatasource)

'顯示圖形
saystring=saystring&"<table border=0 cellpadding=0 cellspacing=0>"
saystring=saystring&"<tr>"
saystring=saystring&"<td>"
saystring=saystring&"
<object classid='clsid:0002E500-0000-0000-C000-000000000046'
id='"&"ChartSpace"&graphiccomp&"0" &"' codebase='"&servername&"iechart.cab'
width="&grpwidth&" height="&grpheight&">"
saystring=saystring&colcontent
saystring=saystring&"</object><br>
<img src=images/blank.gif width=1 height=1>"
saystring=saystring&"</td>"
saystring=saystring&"</tr>"
saystring=saystring&"<tr>"
saystring=saystring&"<td height=10></td>"
saystring=saystring&"</tr>"
saystring=saystring&"
<tr id='tr_"&replace(replace(replace(replace(replace
(filename,".txt",""),".",""),"-",""),"/","")," ","") &"' style='display: none'>"
saystring=saystring&"<td>"
saystring=saystring&"<object classid='clsid:0002E500-0000-0000-C000-000000000046' id='"&"ChartSpace"&graphiccomp&"1" &"'
codebase='"&servername&"iechart.cab' width="&grpwidth&" height="&grpheight&">"
saystring=saystring&rowcontent
saystring=saystring&"</object><br><img src=images/blank.gif width=1 height=1>"
saystring=saystring&"</td>"
saystring=saystring&"</tr>"
saystring=saystring&"</table>"
response.write saystring
Set txtf = nothing
Set fs = nothing %>

圖型資料來源 testdata.txt (注意儲存為 txt檔案) :
* the graphic data source 不可刪除
* 8是指基隆~高雄
* 2是指2000&2001
* 資料中間是以tab分隔

the graphic data source
8
2 2000 2001
基隆 70.0 63
台北 69.0 52
新竹 68.0 46
台中 66.5 68
彰化 66.3 76
嘉義 68.5 55
台南 68.5 65
高雄 70.0 80

*以下檔案內容不可修改

長條圖 Column Clustered

檔案名稱 graphic0.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>9657</x:Width>

<x:Height>6376</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Column</x:Type>

<x:SubType>Clustered</x:SubType>

chgdatasource

<x:ScaleID>102697592</x:ScaleID>

<x:ScaleID>102697732</x:ScaleID>

<x:Overlap>0</x:Overlap>

<x:GapWidth>150</x:GapWidth>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

<x:Axis>

<x:AxisID>102697872</x:AxisID>

<x:ScaleID>102697732</x:ScaleID>

<x:Type>Value</x:Type>

<x:Number>

<x:FormatString>General</x:FormatString>

</x:Number>

<x:MajorGridlines>

</x:MajorGridlines>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Left</x:Placement>

</x:Axis>

<x:Axis>

<x:AxisID>102698164</x:AxisID>

<x:ScaleID>102697592</x:ScaleID>

<x:Type>Category</x:Type>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Bottom</x:Placement>

</x:Axis>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>102697592</x:ScaleID>

</x:Scaling>

<x:Scaling>

<x:ScaleID>102697732</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">


長條圖 Column Stacked

檔案名稱 graphic0-1.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>15240</x:Width>

<x:Height>10160</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Column</x:Type>

<x:SubType>Stacked</x:SubType>

chgdatasource

<x:ScaleID>202164744</x:ScaleID>

<x:ScaleID>202164884</x:ScaleID>

<x:Overlap>100</x:Overlap>

<x:GapWidth>150</x:GapWidth>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

<x:Axis>

<x:AxisID>202165024</x:AxisID>

<x:ScaleID>202164884</x:ScaleID>

<x:Type>Value</x:Type>

<x:Number>

<x:FormatString>General</x:FormatString>

</x:Number>

<x:MajorGridlines>

</x:MajorGridlines>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Left</x:Placement>

</x:Axis>

<x:Axis>

<x:AxisID>202165420</x:AxisID>

<x:ScaleID>202164744</x:ScaleID>

<x:Type>Category</x:Type>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Bottom</x:Placement>

</x:Axis>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>202164744</x:ScaleID>

</x:Scaling>

<x:Scaling>

<x:ScaleID>202164884</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">


長條圖 Column 100% Stacked

檔案名稱 graphic0-2.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>15240</x:Width>

<x:Height>10160</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Column</x:Type>

<x:SubType>100% Stacked</x:SubType>

chgdatasource

<x:ScaleID>214174296</x:ScaleID>

<x:ScaleID>214174436</x:ScaleID>

<x:Overlap>100</x:Overlap>

<x:GapWidth>150</x:GapWidth>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

<x:Axis>

<x:AxisID>214174576</x:AxisID>

<x:ScaleID>214174436</x:ScaleID>

<x:Type>Value</x:Type>

<x:Number>

<x:FormatString>0%</x:FormatString>

</x:Number>

<x:MajorGridlines>

</x:MajorGridlines>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Left</x:Placement>

</x:Axis>

<x:Axis>

<x:AxisID>214174972</x:AxisID>

<x:ScaleID>214174296</x:ScaleID>

<x:Type>Category</x:Type>

<x:MajorTick>Outside</x:MajorTick>

<x:MinorTick>None</x:MinorTick>

<x:Placement>Bottom</x:Placement>

</x:Axis>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>214174296</x:ScaleID>

</x:Scaling>

<x:Scaling>

<x:ScaleID>214174436</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">


圓餅圖 Pie Standard

檔案名稱 graphic1.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>15240</x:Width>

<x:Height>10160</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Pie</x:Type>

<x:SubType>Standard</x:SubType>

chgdatasource

<x:VaryColors/>

<x:ScaleID>163298236</x:ScaleID>

<x:HoleSize>0</x:HoleSize>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>163298236</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">

圓餅圖 Pie Exploded

檔案名稱 graphic1-1.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>15240</x:Width>

<x:Height>10160</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Pie</x:Type>

<x:SubType>Exploded</x:SubType>

chgdatasource

<x:VaryColors/>

<x:ScaleID>219770536</x:ScaleID>

<x:HoleSize>0</x:HoleSize>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>219770536</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">


圓餅圖 Pie Stacked

檔案名稱 graphic1-2.txt (注意儲存為 txt檔案) :

<param name="XMLData" value="<xml xmlns:x='urn:schemas-microsoft-com:office:excel'>

<x:WebChart>

<x:OWCVersion>9.0.0.2710</x:OWCVersion>

<x:Width>15240</x:Width>

<x:Height>10160</x:Height>

<x:DataSource>

<x:Type>OSP</x:Type>

</x:DataSource>

<x:Border>

<x:Color>#000000</x:Color>

</x:Border>

<x:Chart>

<x:PlotArea>

<x:Graph>

<x:Type>Pie</x:Type>

<x:SubType>Stacked</x:SubType>

chgdatasource

<x:VaryColors/>

<x:ScaleID>3541096</x:ScaleID>

<x:HoleSize>0</x:HoleSize>

<x:FirstSliceAngle>0</x:FirstSliceAngle>

</x:Graph>

</x:PlotArea>

<x:Legend>

<x:Placement>Right</x:Placement>

</x:Legend>

</x:Chart>

<x:Scaling>

<x:ScaleID>3541096</x:ScaleID>

</x:Scaling>

</x:WebChart>

</xml>">

<param name="ScreenUpdating" value="-1">
本篇文章發表於2002-06-16 00:00
目前尚無任何回覆
   

回覆
如要回應,請先登入.