創建項目
- 文件 -> 新建 -> 項目 ->
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());