asp.net MVC項目開發之統計圖echarts後台數據的處理(三),mvcecharts
前台顯示的東西,有相應的文檔很容易修改,後台傳遞數據方式才是我們最關心的
首先要記住,我們一步數據使用的是post,那麼後台代碼我們要給方法加上 [HttpPost]注解
不然異步沒有效果
下面上代碼,為了節省時間,字段變量的命名,我用的是英文1,2,3,不要見怪哦

![]()
public ActionResult GetMarriageList(int areaId, int level)
{
List<VwAllPersonInfoModel> allPerList = new List<VwAllPersonInfoModel>();
IVwAllPersonInfoService allPerService = LoadService<IVwAllPersonInfoService>();
Dictionary<string, Object> json = new Dictionary<string, Object>();
DdlDataSrc ddl = new DdlDataSrc();
DataTable dt = new DataTable();
Criteria c = new Criteria();
StringBuilder sb = new StringBuilder();
ddl.getAllChildAreaIds(sb, areaId);
#region 根據區域把獲取的數據放入json
int one = 0;
int two = 0;
int three = 0;
int four = 0;
if (level == 3)
{
c.AddWhere("AreaId", areaId);
allPerList = allPerService.GetAllVwAllPersonInfoModel(c);
}
else if (level != 0)
{
string str = sb.Remove(sb.Length - 1, 1).ToString();
dt = allPerService.GetAllPersonInfoCharts(str, 0, 0);
allPerList = (List<VwAllPersonInfoModel>)ModelConvertHelper<VwAllPersonInfoModel>.ConvertToModel(dt);
}
if (allPerList.Count != 0)
{
for (int i = 0; i < allPerList.Count; i++)
{
switch (allPerList[i].MaticalStatus)//婚姻狀況
{
case 1:
++one;
break;
case 2:
++two;
break;
case 3:
++three;
break;
case 4:
++four;
break;
}
}
json.Add("未婚", one);
json.Add("已婚有配偶", two);
json.Add("離婚", three);
json.Add("喪偶", four);
}
else
{
json.Add("暫無數據", 1);
}
#endregion
return Json(json);
}
View Code
這裡使用 Dictionary<string, Object> json = new Dictionary<string, Object>();Dictionary的結構是這樣的:Dictionary<[key], [value]>提供快速的鍵值查找的方式,把輸入異步給統計圖。
如果數據是單選的,可以使用switch進行判斷,如果是多選的話,請使用if進行判斷。分享出來希望能幫到大家,不足的地方,可以留言,共同進步