效果:
說明:此效果只是簡單的嵌套flash讀取資料庫中某兩個欄位的資料。(【js:http://163.fm/L6X8OAe 提取碼:PRhkACbJ】 【swf:http://163.fm/Nqo2BPU 提取碼:ot6Ws5zn 】 )
事件:初始化載入。
代碼部分:
HTML:
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head runat="server"> 3 <title></title> 4 <script src="flash/FusionCharts.js"type="text/javascript"></script> 5 </head> 6 <body> 7 <form id="form1" runat="server"> 8 <div> 9 <table width="920" align="center" border="0" cellspacing="0" cellpadding="0" id="flash">10 <tr>11 <td>12 <div id="flashGO" style="width: 900px; border: 1px #ccc solid;">13 </div>14 </td>15 </tr>16 </table>17 </div>18 </form>19 20 <script type="text/javascript">21 getchart('flash/Column3D.swf');22 function getchart(str) {23 var chart = new FusionCharts(str, "ChartId", "900", "400");24 chart.setDataXML('<?xml version="1.0" encoding="UTF-8" ?>'+25 '<chart caption="青苹果資料分析" bgColor="#ffffff" xAxisName="實驗室檢測項目" yAxisName="總條數"' +26 ' numberPrefix="" sformatNumberScale="1" syncAxisLimits="10" rotateValues="0" showSum="0" baseFontSize="12">' +27 /***產生柱狀圖*************************************************/28 <%=flash %>29 /************************************************************/30 '</chart>');31 chart.render("flashGO");32 }33 </script>34 35 </body>36 </html>
後台:
1 namespace qiantaoflash 2 { 3 public partial class _Default : System.Web.UI.Page 4 { 5 SqlConnection con = new SqlConnection("server=NEWSPRING;database=QG_Mis;uid=sa;pwd=pass@word1"); 6 protected void Page_Load(object sender, EventArgs e) 7 { 8 GetData(); 9 }10 public string flash = string.Empty;11 protected void GetData()12 {13 string sql = string.Format(@"SELECT TOP 30 * FROM ly_tzk");14 DataSet ds = new DataSet();15 SqlDataAdapter sda = new SqlDataAdapter(sql, con);16 sda.Fill(ds);17 foreach (DataRow dr in ds.Tables[0].Rows)18 {19 flash += "'<set label=" + '"' + dr["xmmc"].ToString() + '"' + "value=" + '"' + dr["MenuID"].ToString() + '"' + "/>'+";20 }21 }22 }23 }