创建项目
- 文件 -> 新建 -> 项目 ->
ASP.NET Web
应用程序(EchartsDemo
) -> 选择模板(Empty
) -> 确定 - 在项目上右击 -> 添加 -> 新建项 ->
OWIN Startup
类(Startup.cs
) - 在项目上右击 -> 添加 -> web窗体(
Default.aspx
) - 在项目上右击 -> 添加 -> 新建项 -> 一般处理程序(
GetFileHandler.ashx
)
编写JS
脚本
采用Ajax
进行定时刷新
$.ajax({
type: 'GET',
url: '/GetFileHandler.ashx',
dataType: 'json',
success: function (result) {
console.log(result);
},
error: function(result) {
console.log(result);
}
});
ASP.NET
后台程序编写
拼接JSON
var rss = new JObject(
new JProperty(
"xAxis", new JObject(
new JProperty("type", "category"),
new JProperty("data", new JArray(date)))),
new JProperty(
"yAxis", new JObject(
new JProperty("type", "value")
)),
new JProperty("series", new JArray(
new object[] { new JObject(new JProperty("data", new JArray(value)),
new JProperty("type", "line")), }
))
);
将拼接的JSON
发送
context.Response.Write(rss.ToString());