MVC實現EChatrs動態折線圖
namespace Echarts資料搭配.Controllers { public class HomeController : Controller { Random r = new Random(); int index = 0; #region 靜態帶面積折線圖 public ActionResult Index() { return View(); } public JsonResult GetJson() { int[] data1 = { 120, 132, 101, 134, 90, 230, 210 }; int[] data2 = { 20, 232, 11, 144, 90, 30, 90 }; int[] data3 = { 180, 12, 161, 84, 60, 230, 10 }; var id1 = new { name = "測試資料1", data = data1, }; var id2 = new { name = "測試資料2", data = data2, }; var id3 = new { name = "測試資料3", data = data3, }; List<object> data = new List<object>(); data.Add(id1); data.Add(id2); data.Add(id3); string[] xcontent = { "a", "b", "c", "d", "e", "f", "g" }; var tld = new { xcontent = xcontent, data = data }; return Json(tld); } #endregion #region 動態折線圖 多條 public ActionResult NextLine() { return View(); } public ActionResult GetNextLineJson() { List<Record> records = new List<Controllers.Record>(); for (int i = 0; i < 200; i++) { records.Add(new Record(i, r)); } DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<Record>)); MemoryStream stream = new MemoryStream(); serializer.WriteObject(stream, records); byte[] dataBytes = new byte[stream.Length]; stream.Position = 0; stream.Read(dataBytes, 0, (int)stream.Length); string jsonstring = Encoding.UTF8.GetString(dataBytes); return Content(jsonstring); } public ActionResult GetNetxtLineAjax() { index++; var records = new Record(index, r); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Record)); MemoryStream stream = new MemoryStream(); serializer.WriteObject(stream, records); byte[] dataBytes = new byte[stream.Length]; stream.Position = 0; stream.Read(dataBytes, 0, (int)stream.Length); string jsonstring = Encoding.UTF8.GetString(dataBytes); return Content(jsonstring); } #endregion #region 動態折線圖 一條 public ActionResult NetTowLine() { return View(); } #endregion } [Serializable] public class Record { private string taizhan_num; //臺站名 private String tem; //溫度 private String hum; //溼度 private String pa; //壓強 private String rain; //雨量 private String win_dir; //風向 private String win_sp; //風速 private String dateStr; //觀測日期(用於Echarts顯示格式) private DateTime date; //觀測日期(原始格式) public Record(int i, Random r) { this.taizhan_num = "臺站名" + i; date = DateTime.Now; tem = (r.Next(0, 100)).ToString(); hum = (r.Next(0, 100)).ToString(); pa = (r.Next(0, 1000)).ToString(); rain = "0.0"; win_dir = (r.Next(0, 100)).ToString(); win_sp = (r.NextDouble() * 20).ToString(); dateStr = date.ToString(); } /// <summary> /// @return 觀測日期值 /// </summary> /// <returns></returns> public String getDateStr() { return dateStr; } /// <summary> /// 設定觀測日期(用於echarts圖表展示 /// </summary> /// <param name="dateStr">待設定觀測日期值</param> public void setDateStr(String dateStr) { this.dateStr = dateStr; } /// <summary> /// 獲取產生該觀測記錄的臺站名稱; /// </summary> /// <returns>臺站名稱</returns> public string getTaizhan_num() { return taizhan_num; } /// <summary> /// 設定產生該觀測記錄的臺站名稱; /// </summary> /// <param name="taizhan_num">待設定臺站名稱</param> public void setTaizhan_num(String taizhan_num) { this.taizhan_num = taizhan_num; } /// <summary> /// 獲取溫度; /// </summary> /// <returns>溫度值</returns> public String getTem() { return tem; } /// <summary> /// 設定溫度; /// </summary> /// <param name="tem">待設定溫度值</param> public void setTem(String tem) { this.tem = tem; } /// <summary> /// 獲取溼度; ///</summary> /// <returns>溼度值</returns> public String getHum() { return hum; } /// <summary> /// 設定溼度; /// </summary> /// <param name="hum">待設定溼度值</param> public void setHum(String hum) { this.hum = hum; } /// <summary> /// 獲取壓強; /// </summary> /// <returns>壓強值</returns> public String getPa() { return pa; } /// <summary> /// 設定壓強; /// </summary> /// <param name="pa">待設定壓強值</param> public void setPa(String pa) { this.pa = pa; } /// <summary> /// 獲取雨量; /// </summary> /// <returns>雨量值</returns> public String getRain() { return rain; } /// <summary> /// 設定雨量; /// </summary> /// <param name="rain">待設定雨量值</param> public void setRain(String rain) { this.rain = rain; } /// <summary> /// 獲取風向; /// </summary> /// <returns>風向值</returns> public String getWin_dir() { return win_dir; } /// <summary> /// 設定風向; /// </summary> /// <param name="win_dir">待設定風向值</param> public void setWin_dir(String win_dir) { this.win_dir = win_dir; } /// <summary> /// 獲取風速; /// </summary> /// <returns>風速值</returns> public String getWin_sp() { return win_sp; } /// <summary> /// 設定風向; /// </summary> /// <param name="win_sp">待設定風向值</param> public void setWin_sp(String win_sp) { this.win_sp = win_sp; } /// <summary> /// 獲取觀測日期; /// </summary> /// <returns>觀測日期</returns> public DateTime getDate() { return date; } /// <summary> /// 設定觀測日期; /// </summary> /// <param name="date">觀測日期值</param> public void setDate(DateTime date) { this.date = date; } }
效果圖展示:
圖一:
圖二:
圖三:
由個人天使最後編輯於:2年前
內容均為作者獨立觀點,不代表八零IT人立場,如涉及侵權,請及時告知。
相關文章
- Flutter 實現平滑曲線折線圖Flutter
- Chart.js繪製動態折線圖JS
- 使用chart.js製作動態折線圖JS
- echarts折線圖Echarts
- echarts - 折線圖Echarts
- R : 折線圖
- 微信小程式折線圖表折線圖加區域圖微信小程式
- matlab畫折線圖Matlab
- echarts 折線圖拼接Echarts
- Flask SocketIO 實現動態繪圖Flask繪圖
- vue 實現動態拓撲圖Vue
- ECHARTS-折線圖不顯示資料 控制折線圖顏色Echarts
- excel折線圖自定x軸y軸 excel折線圖xy設定Excel
- PyQtGraph繪製折線圖QT
- AnyChart繪製折線圖
- Matplotlib 繪製折線圖
- MATLAB 繪製折線圖Matlab
- 巧用 CSS 實現動態線條 Loading 動畫CSS動畫
- Python畫圖——matplotlib(普通折線圖)Python
- Echarts資料視覺化:圖表篇(2)—— 折線圖、堆疊面積折線圖Echarts視覺化
- PHP 生成折線圖和餅圖等PHP
- Python視覺化-折線圖Python視覺化
- 前端使用 Konva 實現視覺化設計器(22)- 繪製圖形(矩形、直線、折線)前端視覺化
- Android 折線圖之hellocharts (餅狀圖)餅圖Android
- 如何實現一鍵線上自動摳圖?
- Qt實現炫酷啟動圖-動態進度條QT
- 柱狀圖多系列php動態實現(ec)PHP
- amCharts繪製帶趨勢線折線圖
- spring boot+bootstrap實現動態輪播圖實戰Spring Boot
- D3.js上手——折線圖JS
- Python視覺化(1):折線圖Python視覺化
- echart折線圖異常多出一條連線線
- 原生JS實現拋物線動畫以及動態模糊效果JS動畫
- PaddlePaddle動態圖實現Resnet(眼底篩查為例)
- PaddlePaddle動態圖實現VGG(眼底篩查為例)
- amCharts繪製折線圖和柱狀圖混合
- 資料視覺化圖表之折線圖視覺化
- 前端使用 Konva 實現視覺化設計器(19)- 連線線 - 直線、折線前端視覺化