-
C#教程之C#简单嵌套flash读取数据的实现代码
效果:
说明:此效果只是简单的嵌套flash读取数据库中某两个字段的数据。(【js下载地址:http://xiazai.jb51.net/201311/yuanma/FusionCharts(jb51.net).js】 【swf下载地址:http://pan.baidu.com/s/1b2O9Q】 )
事件:初始化加载。
代码部分:
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="flash/FusionCharts(jb51.net).js"type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="920" align="center" border="0" cellspacing="0" cellpadding="0" id="flash">
<tr>
<td>
<div id="flashGO" style="width: 900px; border: 1px #ccc solid;">
</div>
</td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
getchart('flash/Column3D(jb51.net).swf');
function getchart(str) {
var chart = new FusionCharts(str, "ChartId", "900", "400");
chart.setDataXML('<?xml version="1.0" encoding="UTF-8" ?>'+
'<chart caption="青苹果数据分析" bgColor="#ffffff" xAxisName="试验室检测项目" yAxisName="总条数"' +
' numberPrefix="" sformatNumberScale="1" syncAxisLimits="10" rotateValues="0" showSum="0" baseFontSize="12">' +
/***生成柱状图*************************************************/
<%=flash %>
/************************************************************/
'</chart>');
chart.render("flashGO");
}
</script>
</body>
</html>
后台:
namespace qiantaoflash
{
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=NEWSPRING;database=QG_Mis;uid=sa;pwd=pass@word1");
protected void Page_Load(object sender, EventArgs e)
{
GetData();
}
public string flash = string.Empty;
protected void GetData()
{
string sql = string.Format(@"SELECT TOP 30 * FROM ly_tzk");
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
flash += "'<set label=" + '"' + dr["xmmc"].ToString() + '"' + "value=" + '"' + dr["MenuID"].ToString() + '"' + "/>'+";
}
}
}
}