其中在connectionStrings中,指定了当前access数据库的文件,如果是SQL SERVER 2008的话,则修改为:
<
add name
=
"
SQLServerConnection
"
providerName
=
"
System.Data.Odbc
"
connectionString = " Driver={SQL
Server};;uid = USERNAME;pwd = PASSWORD;server = HOST;database = DATABASE_NAME " />
connectionString = " Driver={SQL
Server};;uid = USERNAME;pwd = PASSWORD;server = HOST;database = DATABASE_NAME " />
5) 在页面中的页面开始部分,加入对FusionCharts.js的引用:
<
script type
=
"
text/javascript
"
src
=
"
FusionCharts/FusionCharts.js
"
></
script
>
6) 同样,在页面中添加一个button,一个literall控件,编写如下代码:
StringBuilder xmlData
=
new
StringBuilder();
string query = "" ;
query = " select Team, Points from IPL_POINTS " ;
DbConn db = new DbConn(query);
xmlData.AppendFormat( " <chart> " );
while (db.ReadData.Read())
{
// Generate <set name='..' value='..' />
xmlData.AppendFormat( " <set label='{0}' value='{1}' /> " ,
db.ReadData[ " Team " ].ToString(), db.ReadData[ " Points " ].ToString());
}
xmlData.AppendFormat( " </chart> " );
Literal1.Text = FusionCharts.RenderChart( " FusionCharts/Column2D.swf " , "" ,
xmlData.ToString(), " chart1 " , " 500 " , " 400 " , false , true );
string query = "" ;
query = " select Team, Points from IPL_POINTS " ;
DbConn db = new DbConn(query);
xmlData.AppendFormat( " <chart> " );
while (db.ReadData.Read())
{
// Generate <set name='..' value='..' />
xmlData.AppendFormat( " <set label='{0}' value='{1}' /> " ,
db.ReadData[ " Team " ].ToString(), db.ReadData[ " Points " ].ToString());
}
xmlData.AppendFormat( " </chart> " );
Literal1.Text = FusionCharts.RenderChart( " FusionCharts/Column2D.swf " , "" ,
xmlData.ToString(), " chart1 " , " 500 " , " 400 " , false , true );
在上面的代码中,首先是通过连接数据库,传入SQL查询语句,获得数据结果集,然后循环读取,再将数据组合成符合FusionCharts规范的XML格式文件即可,其中
xmlData.AppendFormat(
"
<set label='{0}' value='{1}' />
"
,
db.ReadData[ " Team " ].ToString(), db.ReadData[ " Points " ].ToString());
db.ReadData[ " Team " ].ToString(), db.ReadData[ " Points " ].ToString());
分别对label及value传入从数据库中取出来的值,最后依然使用FusionCharts的RenderChart方法,产生图表,跟第一种及第二种方法一样,生成的图表如下:
小 结
在ASP.NET中使用Fusion Charts的方法其实很简单,无论是从数据库中获得数据源还是从XML获得数据源,只需要生成符合Fusion Charts规范的XML文件即可。更多的Fusion Charts的使用方法及API请参考其官方网站及文档。