Ret_char_data = [] # expense Subtotal list ret_char_data_root = [] # Expense Subtotal list includes total funding budget_obj = models. Budget.objects.filter (id=request. Get.get ("id")). First () Payment_year = Time.strptime (Budget_obj.year_budget, "%Y") [0] payment_previous_year = Time.strptime (Budget_obj.year_budget, "%Y") [0]-1 Sum_pay = models. Payment.objects.filter (payment_time__year=payment_year). VALUES (). Aggregate (Sum ("Payment_amount")) # Total annual expenditure Payment _list = models. Payment.objects.filter (payment_time__year=payment_year). VALUES ("Payment_project__project_property"). Annotate ( Sum ("Payment_amount") # Gets the expense summary data by project Property Payment_list_previous_year = models. Payment.objects.filter (payment_time__year=payment_previous_year). VALUES ("Payment_project__project_property"). Annotate (Sum ("Payment_amount")) Property_tuple = models. Operamaintproject._meta.model.property_choices # obtained ((0, ' Autonomous maintenance '), (1, ' professional Generation '), (2, ' outsourced maintenance '), (3, ' Emergency Repair '), (4, ' spare parts procurement '), (5, ' Other ')) ret_list = [] Ret_list_previous_year = [] Budget = Budget_obj.reply_quota*10000-sum_pay["Payment_amount__sum"] # remaining Funds Budget_dic = {"Budget": Budget} for property in Property_tuple:char_dic = {} char_dic_root = {} char_dic[' type '] = property[1] char_dic_root[' type '] = property[1] char_dic[' money ' = 0 char_dic_root[' money '] = 0 For Pay_item in Payment_list:if pay_item["payment_project__project_property"] = = Property[0]: char_dic[' type '] = PROPERTY[1] char_dic_root[' type '] = property[1] char_dic[' money '] = pay_item[' payment_amount__sum '] char_dic_root[' Money '] =float (round ((pay_item[' payment_amount__sum ']/(budget_obj.reply_quota*10000)) *100,1)) Ret_char_ Data.append (char_dic) ret_char_data_root.append (char_dic_root) Sum_money = 0 for obj in Ret_char_data_root:sum_money = Sum_money +float (obj["Money"]) Char_dic_remainder = {} char_dic_remainder[' type '] = ' remaining funds ' char_dic_remainder[' financial '] = 100-sum_money Ret_char_data_root.append (char_dic_remainder) ret_char_data_root = Json.dumps (ret_char_data_root) # Char_dic_total = {} # char_dic_total[' type '] = ' total funding ' # char_dic_total[' money '] = str (budget_obj.reply_quota*10000) # ret_char_data_root.append (char_dic_total) print (ret_char_data_root) char_dic_sum={} char_dic_sum[' type '] = ' total expenditure ' char_dic_sum[' money ' = str (sum_pay[' payment_amount__sum ']) ret_char_ Data.append (Char_dic_sum) return render (Request, "opera_maint/budget_mgr/budget_analysis.html", {"Ret_list": ret_ List, "Ret_list_previous_year": Ret_list_previous_year, "property_tuple": Property_tuple, "Ret_char_data": Ret_char_ Data, "Ret_char_data_root": Ret_char_data_root,})
Front End:
var _dataset = DataSet, DataView = _dataset.dataview; Front-end Fetch list var temp_data = ' {ret_char_data_root|safe}} '; Console.log (data,typeof (data)); At this point temp_data is a string var data =json.parse (Temp_data); Turn to JSON object Console.log (data,typeof (data)); This is already an object. You cannot use Json.parse (' {{ret_char_data_root|safe}} ') directly. Want to transfer a bit. var dv1 = new DataView (); Dv1.source (data). Transform ({type: ' percent ', field: ' Money ', Dimension: ' Type ', As: ' percent '}); var Chart1 = new G2. Chart ({container: ' MountNode1 ', Forcefit:true, height:window.innerHeight}); Chart1.source (DV1, {percent: {formatter:function Formatter (val) {VA L = val * 100 + '% '; return Val; } } }); Chart1.coord (' theta '); Chart1.tooltip ({showtitle:false, itemtpl: ' <li><span style= ' background-color:{color}; class= "G2-tooltip-marker" ></span>{name}: {value}</li> '}); Chart1.intervalstack (). Position (' percent '). Color (' type '). Label (' percent ', {offset: -40,//Autorota Te:false, TextStyle: {rotate:0, textAlign: ' Center ', Shadowblur : 2, Shadowcolor: ' Rgba (0, 0, 0,.) '}). tooltip (' Type*percent ', function (item, Perce NT) {percent = percent * 100 + '% '; return {name:item, value:percent}; }). style ({linewidth:1, stroke: ' #fff '}); Chart1.render (); </script>
Django returns the page and JSON format list to the front-end ANTV chart for use.