關於ASP下建立XML檔案並調用amcharts 畫圖的執行個體

來源:互聯網
上載者:User

 

文章中包含二個部分,組建檔案名稱和檔案內容;調用畫圖顯示圖表;

 

做好後的執行個體在下載欄中可以找到:

 

http://download.csdn.net/source/2831164

 

下面是如何組建檔案的代碼,做好的執行個體的路徑有小小修改已便符合實際情況。

 

<!--#include file="conn.asp"-->

<!--#include file="mycss.asp"-->

<%

 

Set fs=server.CreateObject("scripting.filesystemobject") 

mainkey=request("mainkey")

modkey=request("modkey")

srs=request("srs")

filerorw=request("rorw")

select case modkey

case "year"

mytitle="Machine Breakdown Type Reason Frequency "&srs& " of "&year(mainkey)&"Y"

filename="BreakdownTypeReason"&year(mainkey)&"Y.xml"

wherestr=wherestr&" and year(BreakdownTime)="&year(cdate(mainkey))

case "month"

mytitle="Machine Breakdown Type Reason Frequency "&srs& " of "&year(mainkey)&"Y-"&month(mainkey)&"M"

filename="BreakdownTypeReason"&year(mainkey)&"-"&month(mainkey)&"M.xml"

wherestr=wherestr&" and year(BreakdownTime)="&year(cdate(mainkey))&" and month(BreakdownTime)="&month(cdate(mainkey)) 

case "week"

se=cdate(year(date)&"-01-01") 

weeks=datediff( "ww",se,mainkey) 

mytitle="Machine Breakdown Type Reason Frequency "&srs& " of "&year(mainkey)&"Y-"&weeks&"Week"

filename="BreakdownTypeReason"&year(mainkey)&"-"&weeks&"W.xml"

tempdate1=dateadd("d",1-weekday(cdate(mainkey)),mainkey)

tempdate2=dateadd("d",7-weekday(cdate(mainkey)),mainkey)

wherestr=wherestr&" and BreakdownTime>='"&tempdate1&"' and BreakdownTime<='"&tempdate2&"'"

case else

se=cdate(year(date)&"-01-01") 

weeks=datediff( "ww",se,mainkey) 

mytitle="Machine Breakdown Type Reason Frequency "&srs& " of "&year(mainkey)&"Y-"&weeks&"Week"

filename="BreakdownTypeReason"&year(mainkey)&"-"&weeks&"W.xml"

tempdate1=dateadd("d",1-weekday(cdate(mainkey)),mainkey)

tempdate2=dateadd("d",7-weekday(cdate(mainkey)),mainkey)

wherestr=wherestr&" and BreakdownTime>='"&tempdate1&"' and BreakdownTime<='"&tempdate2&"'"

end select

filepath="xml/"&filename

fileallname=Server.MapPath(filepath) 

wherestr=wherestr&" and BreakdownCode='"&srs&"' " 

sqlstr="select breakdowncodedescription,count(codeid)as countcode from BreakdownView where breakdownid>0 "&wherestr&" group by breakdowncodedescription,CodeID order by countcode desc"

 

if not fs.FileExists(fileallname) or filerorw="write" then

'sqlstr="select codeid as breakdowncodedescription,count(codeid)as countcode from BreakdownView where breakdownid>0 "&wherestr&" group by CodeID order by countcode desc"

 

 

 

 

dim childNode,CreateCDATASection

set xmldoc=Server.createobject("Msxml2.DOMDocument.4.0")

Set version = xmldoc.createProcessingInstruction("xml","version='1.0' encoding='utf-8'")

xmldoc.appendchild(version)

Set root = xmldoc.CreateNode(1,"pie","")

xmldoc.appendChild(root)

 

set rs=conn.execute (sqlstr,0,1)

i=0

do while not rs.eof 

if i=0 then

set childNode=xmldoc.CreateNode(1,"slice","")

childNode.SetAttribute "title",rs("breakdowncodedescription")

childNode.SetAttribute "pull_out","true"

childnode.text=rs("countcode")

'Set CreateCDATASection = xmldoc.createCDATASection(rs("countcode"))

'childNode.appendChild(createCDATASection)

 

else

set childNode=xmldoc.CreateNode(1,"slice","")

childNode.SetAttribute "title",rs("breakdowncodedescription")

childnode.text=rs("countcode")

'Set CreateCDATASection = xmldoc.createCDATASection(rs("countcode"))

'childNode.appendChild(createCDATASection)

end if

rs.movenext

i=i+1

root.appendChild childNode

response.write err.description

loop

xmldoc.save(Server.Mappath(filepath))

set rs=nothing

end if

 

 

set fs=nothing

xmldoc.close

set xmldoc=nothing

 

%>

 

//以下是調用XML檔案畫圖表。

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Machine Breakdown Type Reason Frequency of <%=filename%></title>

</head>

 

<body>

<% response.write "<strong>"&mytitle&"</strong>" %>

<!-- saved from url=(0013)about:internet -->

<!-- ampie script-->

  <script type="text/javascript" src="../chart/dup/ampie/swfobject.js"></script>

<div id="flashcontent">

<strong>You need to upgrade your Flash Player</strong>

</div>

 

<script type="text/javascript">

// <![CDATA[

var so = new SWFObject("../chart/dup/ampie/ampie.swf", "ampie", "800", "680", "8", "#FFFFFF");

so.addVariable("path", "../chart/dup/ampie/");

so.addVariable("settings_file", encodeURIComponent("../chart/dup/ampie/ampie_settings.xml"));                // you can set two or more different settings files here (separated by commas)

<% response.write "var filename="""&filename&""";" %>

so.addVariable("data_file", encodeURIComponent("../tpm/xml/"+filename));

 //這裡的檔案名稱和路徑是符合伺服器上的,請自行修改。

// so.addVariable("chart_data", encodeURIComponent("<settings>...</settings>"));                   // you can pass chart data as a string directly from this file

// so.addVariable("chart_settings", encodeURIComponent("data in CSV or XML format"));              // you can pass chart settings as a string directly from this file

// so.addVariable("additional_chart_settings", encodeURIComponent("<settings>...</settings>"));    // you can append some chart settings to the loaded ones

//  so.addVariable("loading_settings", "LOADING SETTINGS");                                         // you can set custom "loading settings" text here

//  so.addVariable("loading_data", "LOADING DATA");                                                 // you can set custom "loading data" text here

//  so.addVariable("preloader_color", "#999999");

//  so.addVariable("error_loading_file", "ERROR LOADING FILE");                                     // you can set custom "error loading file" text here

so.write("flashcontent");

// ]]>

</script>

<!-- end of ampie script -->

<%

 

response.write "<div id='scrollDiv' style='width:100%; overflow: auto;position: absolute; left:850px; top:25px;height: 80%;'>"

response.write "<table id='accountTable' border='0' cellpadding='0' cellspacing='0' width='200'><thead class='fixedHeader'>"

response.write "<tr class='FixedTitleRow'><th>BreakdownType</th><th>Count</th></tr></thead>"

set rs=conn.execute (sqlstr,0,1)

do while not rs.eof

response.write "<tr>"

response.write "<td>"&rs.fields(0).value&"</td>"

response.write "<td>"&rs.fields(1).value&"</td>"

response.write "</tr>"

rs.movenext

loop

set rs=nothing

response.write "</tbody></table></div>"

%>

</body>

</html>

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.