作者:真实的灿灿1978 | 来源:互联网 | 2023-06-21 10:02
做GIS或其他内部数据统计项目的应该对FusionCharts也不会太陌生,简单易用已无需多说什么了,只是有时候框架不同,实现起来也稍有差异引用dll调用FusionCharts类的静态方
做GIS或其他内部数据统计项目的应该对FusionCharts也不会太陌生,简单易用已无需多说什么了,只是有时候框架不同,实现起来也稍有差异
引用dll调用FusionCharts类的静态方法RenderChartHTML 返回html绑定在数据控件上更为符合webform;
使用JS代码new FusionCharts对象,调用对象的setDataXML或者setDataURL方法更为符合MVC
1、HTML+JS
2、ASP.NET Webform
protected void Page_Load(object sender, EventArgs e)
{
Panel1.Controls.Clear();
Dictionary data = new Dictionary() {
{"香蕉",12},
{"橘子",55},
{"苹果",23},
{"人参果",20}
};
Panel1.Controls.Add(ShowNewChart(data, DropDownList1.SelectedValue, "数量"));
}
///
/// 绑定图形数据
///
/// 数据
/// 图形类型
/// 柱状图显示标题
///
private LiteralControl ShowNewChart(Dictionary dic, string Type, string yAxisName)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
foreach (string key in dic.Keys)
{
sb.AppendFormat("", key, dic[key]);
}
sb.AppendFormat("");
string types = "";
if (Type == "1")
{
//饼状图 swf路径
types = "package/FusionCharts/Charts/Pie3D.swf";
}
else if (Type == "0")
{
//柱状图
types = "package/FusionCharts/Charts/2Column3D.swf";
}
return new LiteralControl(FusionCharts.RenderChartHTML(types, "", sb.ToString(), "chart1", "650", "250", false, false));
}
3、ASP.NET MVC
//--------------------------view----------------------------------
//--------------------------action----------------------------------
public ActionResult Index()
{
Dictionary
data = new Dictionary() {
{"香蕉",12},
{"橘子",55},
{"苹果",23},
{"人参果",20}
};
ViewData.Model = GetChartXml(data, "水果数量");
return View();
}
///
/// 绑定图形数据
///
/// 数据
/// 图形类型
/// 柱状图显示标题
///
private string GetChartXml(Dictionary dic, string yAxisName)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
foreach (string key in dic.Keys)
{
sb.AppendFormat("", key, dic[key]);
}
sb.AppendFormat("");
return sb.ToString();
}
源码:http://files.cnblogs.com/NotAnEmpty/FusionCharts.rar