Dynamic binding of HighChat to data backend binding (3) and highchat binding
Today, I read some blogs from some of the bosses. Now I want to share some of them as a reference for the future.
Not to mention the code
1. Background code
public ActionResult Ajax2() { ReportData reportData = new ReportData(); string[] key = { "2017-08-01", " 2017-08-02", "2017-08-03", "2017-08-04", "2017-08-05", "2017-08-06", "2017-08-07", "2017-08-08", " 2017-08-09", "2017-08-10", "2017-08-11", "2017-08-12" }; reportData.categories = key; double?[] value = { 3.9, 4.6, 5.7, 10.5, 1.9, 15.2, 15.0, 16.6, 19.2, 10.0, 5.2, 46.8 }; double?[] value1 = { 3.9, 3.6, 5.7, 8.5, 1.9, 15.2, 12.0, 16.6, 12.2, 10.0, 5.1, 46.8 }; ReportItem ri1 = new ReportItem() { data = value, name = "Agent Used" }; reportData.ReportItems.Add(ri1); ReportItem ri2 = new ReportItem() { data = value1, name = "Emission" }; reportData.ReportItems.Add(ri2); return Json(reportData); }
Defines entity classes to receive data
public class ReportData { public string[] categories { get; set; } public List<ReportItem> ReportItems = new List<ReportItem>(); } public class ReportItem { public string name { get; set; } public double?[] data { get; set; } }
The front-end is also very simple
@ {Layout = null ;}<! DOCTYPE html>
Ga feels that this is the simplest way. All the data is bound from the backend, and the front-end is only responsible for display. It was learned only after reading many articles.
Download link: http://pan.baidu.com/s/1skOrBQX