$(function () { function initSubjectBadEcharts(xAxis_data, series_data) { var option = { animation: false, title: { text: "人", x: "left", y: "top", textStyle: { color: "#5F6E82", fontSize: $.UnitUtil.mm2px(3), fontWeight: 500, }, }, color: ["#5C99FF"], legend: { itemWidth: $.UnitUtil.mm2px(2), itemHeight: $.UnitUtil.mm2px(2), top: "bottom", data: ["违纪人数"], }, grid: { top: $.UnitUtil.mm2px(10), left: 0, right: 0, bottom: $.UnitUtil.mm2px(8), containLabel: true, }, xAxis: [ { type: "category", data: xAxis_data, axisLabel: { color: "#5F6E82", //更改坐标轴文字颜色 interval: 0 }, axisTick: { alignWithLabel: true, }, boundaryGap: true, triggerEvent: true, axisLine: { show: true, //是否显示轴线 lineStyle: { color: "#DADADA", //刻度线的颜色 }, }, }, ], yAxis: [ { type: "value", axisTick: { show: false, //刻度 }, axisLine: { show: false, //是否显示轴线 lineStyle: { color: "#DADADA", //刻度线的颜色 }, }, splitLine: { //网格线 lineStyle: { type: "dotted", //设置网格线类型 dotted:虚线 solid:实线 }, show: true, //隐藏或显示 }, axisLabel: { color: "#5F6E82", //更改坐标轴文字颜色 }, }, ], series: [ { name: "违纪人数", type: "bar", barWidth: $.UnitUtil.mm2px(5), // 柱状图最小高度 barMinHeight: $.UnitUtil.mm2px(2), barGap: 0, label: { normal: { show: true, align: "center", verticalAlign: "bottom", position: "top", distance: 0, formatter: "{c}", }, }, data: series_data, }, ], }; var myEcharts = echarts.init(document.querySelector(".section_3 #subjectBadEcharts")); myEcharts.clear(); myEcharts.setOption(option); } var parameter = $(".section_3_html_root").data("page-params"); parameter = JSON.parse(parameter); var subjectid_subjectname = {}; var subjectid_num = {}; var classes = []; parameter = $.map(parameter, function(paraItem) { paraItem.subjectjson = paraItem.subjectjson ? JSON.parse(paraItem.subjectjson) : []; var subjects = {}; var class_num = 0; $.each(paraItem.subjectjson, function(index, subjectItem) { subjectid_subjectname[subjectItem.subjectid] = subjectItem.subjectname; if (subjectid_num[subjectItem.subjectid]) { subjectid_num[subjectItem.subjectid] += subjectItem.num; } else { subjectid_num[subjectItem.subjectid] = subjectItem.num; } subjects[subjectItem.subjectid] = { num: subjectItem.num, nrate: subjectItem.nrate, }; class_num += subjectItem.num; }); classes.push({ classid: paraItem.classid, classname: paraItem.classname, class_num: class_num, subjects: subjects }); return paraItem; }); var xAxis_data = []; var series_data = []; var maxSubjectInfo = { num: 0, subjectname: "" }; var badTableHeadTr1Html = '班级'; var badTableHeadTr2Html = ''; for (var subjectid in subjectid_subjectname) { xAxis_data.push(subjectid_subjectname[subjectid]); series_data.push(subjectid_num[subjectid]); if(maxSubjectInfo.num < subjectid_num[subjectid]) { maxSubjectInfo = { num: subjectid_num[subjectid], subjectname: subjectid_subjectname[subjectid] }; } // class="w29mm" badTableHeadTr1Html += '' + subjectid_subjectname[subjectid] + ''; badTableHeadTr2Html += '人数比例'; } $(".section_3 .subjectBadMaxNum").text(maxSubjectInfo.subjectname); initSubjectBadEcharts(xAxis_data, series_data); var maxClassInfo = { num: 0, classname: "" }; var badTableTbodyHtml = ""; for (var i = 0; i < classes.length; i++) { var classItem = classes[i]; var trHtml = '
' + classItem.classname + '
' if (maxClassInfo.num < classItem.class_num) { maxClassInfo = { num: classItem.class_num, classname: classItem.classname }; } for (var subjectid in subjectid_subjectname) { series_data.push(subjectid_num[subjectid]); trHtml += '
' + (classItem.subjects[subjectid].num || 0) + '
' + (classItem.subjects[subjectid].nrate || 0) + '%
' } badTableTbodyHtml += '' + trHtml + ''; } $(".section_3 .classBadMaxNum").text(maxClassInfo.classname); $(".section_3 .badTableHeadTr1").html(badTableHeadTr1Html); $(".section_3 .badTableHeadTr2").html(badTableHeadTr2Html); $(".section_3 .badTableTbody").html(badTableTbodyHtml); });