在ASP.NET中使用Highcharts js图表
从事过ASP.NET开发的可能都会接触到一些图表控件,比如OWC、ZendGraph等等,这些控件都有一个特点,那就是我们可以像操作.NET中的对象一样控制它们的某些属性,有可能在本地开发好了上传到服务器端部署运行的时候会出现权限问题而导致不能正常运行。本篇周公讲述一个JavaScript的图表控件,不要小看了这个JavaScript图表控件,它能生成各种常见的图表。
编码
为了便于演示,周公在创建ASP.NET页面的时候使用了单页模式,整个页面的代码如下:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<mce:script runat="server"><!--
public string result = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
string graphType = ddlGraphType.SelectedValue;
graphType = graphType.ToLower();
switch (graphType)
{
case "line": result=OutputLine(); break;
case "spline": result = OutputSpline(); break;
case "area": result = OutputArea(); break;
case "areaspline": result = OutputAreaSpline(); break;
case "column": result = OutputColumn(); break;
case "bar": result = OutputBar(); break;
case "pie": result = OutputPie(); break;
case "scatter": result = OutputScatter(); break;
}
}
private string OutputLine()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/line.js"), Encoding.UTF8))
{
StringBuilder buffer = new StringBuilder(reader.ReadToEnd());
buffer.Replace("{#title#}", "周公的演示例子");
result = buffer.ToString();
}
return result;
}
private string OutputSpline()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/spline.js"), Encoding.UTF8))
{
StringBuilder buffer = new StringBuilder(reader.ReadToEnd());
buffer.Replace("{#title#}", "周公的演示例子");
result = buffer.ToString();
}
return result;
}
private string OutputArea()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/area.js"), Encoding.UTF8))
{
StringBuilder buffer = new StringBuilder(reader.ReadToEnd());
buffer.Replace("{#title#}", "周公的演示例子");
result = buffer.ToString();
}
return result;
}
private string OutputAreaSpline()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/areaspline.js"), Encoding.UTF8))
{
StringBuilder buffer = new StringBuilder(reader.ReadToEnd());
buffer.Replace("{#title#}", "周公的演示例子");
result = buffer.ToString();
}
return result;
}
private string OutputColumn()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/column.js"), Encoding.UTF8))
{
StringBuilder buffer = new StringBuilder(reader.ReadToEnd());
buffer.Replace("{#title#}", "周公的演示例子");
result = buffer.ToString();
}
return result;
}
private string OutputBar()
{
string result = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/js/template/bar.js"), Encoding.UTF8))
{
 
补充:Web开发 , ASP.Net ,