ASP.NET 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());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章