ASP.NET WebForm echarts初試隨筆

創建項目

  1. 文件 -> 新建 -> 項目 -> ASP.NET Web應用程序(EchartsDemo) -> 選擇模板(Empty) -> 確定
  2. 在項目上右擊 -> 添加 -> 新建項 -> OWIN Startup 類(Startup.cs)
  3. 在項目上右擊 -> 添加 -> web窗體(Default.aspx)
  4. 在項目上右擊 -> 添加 -> 新建項 -> 一般處理程序(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());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章