Asp.net MVC project development Statistical Chart echarts background data processing (3), mvcecharts
The items displayed on the front end are easily modified with corresponding documents. The data transmission method on the back end is what we are most concerned about.
First of all, remember that we use post as the data in one step, so we need to add the [HttpPost] annotation to the method in the background code.
Otherwise, Asynchronization is ineffective.
The code below is used to save time and Name field variables. I use English letters 1, 2, and 3. Don't be surprised.
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 puts the obtained data into 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) // marital status {case 1: ++ one; break; case 2: ++ two; break; case 3: ++ three; break; case 4: ++ four; break;} json. add ("Unmarried", one); json. add ("Married with spouse", two); json. add ("divorce", three); json. add ("zombie", four);} else {json. add ("no data", 1) ;}# endregion return Json (json );}View Code
Here we use Dictionary <string, Object> json = new Dictionary <string, Object> (); the structure of Dictionary is as follows: Dictionary <[key], [value]> provides a fast key-value search method to asynchronously display the input to the statistics graph.
If the data is single-choice, you can use switch for determination. if multiple data is selected, use if for determination. I hope to help you with your feedback and make progress together.