You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

section_2_level.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. $(function () {
  2. //各班等级分析
  3. function initclassLevelEcharts(list) {
  4. var xAxis_data = [],
  5. series_data = [],
  6. legend_data = [],
  7. levelRateObj = {},
  8. levelNumObj = {},
  9. levelrangeObj = [];
  10. $.each(list, function (key, item) {
  11. if ($.inArray(item.classname, xAxis_data) == -1) {
  12. xAxis_data.push(item.classname)
  13. }
  14. if ($.inArray(item.rankname + "类", legend_data) == -1) {
  15. legend_data.push(item.rankname + "类")
  16. }
  17. if ($.inArray(item.rankrange, levelrangeObj) == -1) {
  18. levelrangeObj.push(item.rankrange)
  19. }
  20. if (!levelRateObj[item.rankname + '类']) {
  21. levelRateObj[item.rankname + '类'] = [];
  22. }
  23. levelRateObj[item.rankname + '类'].push(item.sturate);
  24. if (!levelNumObj[item.rankname + '类']) {
  25. levelNumObj[item.rankname + '类'] = [];
  26. }
  27. levelNumObj[item.rankname + '类'].push(
  28. item.stunum
  29. );
  30. });
  31. $.each(legend_data, function (key, item) {
  32. series_data.push({
  33. name: item,
  34. type: "bar",
  35. stack: "总量",
  36. barWidth: 32,
  37. // 柱状图最小高度
  38. barMinHeight: 16,
  39. showBackground: true, // 柱状图显示背景
  40. backgroundStyle: {
  41. color: "#F3F4F5"
  42. },
  43. itemStyle: {
  44. normal: {
  45. barBorderRadius: [4, 4, 4, 4]
  46. }
  47. },
  48. label: {
  49. normal: {
  50. show: true,
  51. align: "center",
  52. verticalAlign: "middle",
  53. position: "inside",
  54. distance: 0,
  55. color: "#fff",
  56. formatter: function (params) {
  57. return levelNumObj[params.seriesName][params.dataIndex] || 0;
  58. }
  59. }
  60. },
  61. data: levelNumObj[item]
  62. });
  63. });
  64. showgraphicaldata(xAxis_data, legend_data, levelrangeObj, list);
  65. var option = {
  66. color: ["#5C99FF", "#ff5f56", "#5EC5C8", "#f1982b", "#6e5eff"],
  67. animation: false,
  68. title: {
  69. text: "%",
  70. x: "left",
  71. y: "top",
  72. textStyle: {
  73. color: "#5F6E82",
  74. fontSize: $.UnitUtil.mm2px(3),
  75. fontWeight: 500,
  76. },
  77. },
  78. legend: {
  79. itemWidth: $.UnitUtil.mm2px(2),
  80. itemHeight: $.UnitUtil.mm2px(2),
  81. top: "bottom",
  82. data: legend_data,
  83. },
  84. grid: {
  85. top: $.UnitUtil.mm2px(10),
  86. left: 0,
  87. right: 0,
  88. bottom: $.UnitUtil.mm2px(8),
  89. containLabel: true,
  90. },
  91. xAxis: [{
  92. type: "category",
  93. data: xAxis_data,
  94. axisLabel: {
  95. color: "#5F6E82", //更改坐标轴文字颜色
  96. interval: 0
  97. },
  98. axisTick: {
  99. alignWithLabel: true,
  100. },
  101. boundaryGap: true,
  102. triggerEvent: true,
  103. axisLine: {
  104. show: true, //是否显示轴线
  105. lineStyle: {
  106. color: "#DADADA", //刻度线的颜色
  107. },
  108. },
  109. }, ],
  110. yAxis: [{
  111. type: "value",
  112. axisTick: {
  113. show: false, //刻度
  114. },
  115. axisLine: {
  116. show: false, //是否显示轴线
  117. lineStyle: {
  118. color: "#DADADA", //刻度线的颜色
  119. },
  120. },
  121. splitLine: {
  122. //网格线
  123. lineStyle: {
  124. type: "dotted", //设置网格线类型 dotted:虚线 solid:实线
  125. },
  126. show: true, //隐藏或显示
  127. },
  128. axisLabel: {
  129. color: "#5F6E82", //更改坐标轴文字颜色
  130. },
  131. }, ],
  132. series: series_data
  133. };
  134. var myEcharts = echarts.init(document.querySelector(".section_2_level #classLevelEcharts"));
  135. myEcharts.clear();
  136. myEcharts.setOption(option);
  137. }
  138. //图表数据
  139. function showgraphicaldata(xAxis_data, legend_data, levelrangeObj, list) {
  140. //图表数据
  141. var arr = JSON.parse(JSON.stringify(list));
  142. var goodTableHeadTr1Html = '<th rowspan="2">班级</th>';
  143. var goodTableHeadTr2Html = '';
  144. var goodTableTbodyHtml = "";
  145. $.each(legend_data, function (idx, item) {
  146. goodTableHeadTr1Html += '<th colspan="2">' + item + levelrangeObj[idx] + '</th>';
  147. goodTableHeadTr2Html += '<th>人数</th><th>比例</th>';
  148. });
  149. $.each(xAxis_data, function (idx, item) {
  150. var trHtml = '<td><div class="my_cell">' + item + '</div></td>'
  151. var classs = $.grep(arr, function (val) {
  152. return val.classname == item;
  153. });
  154. $.each(legend_data, function (idx, item) {
  155. var rank = $.grep(classs, function (val) {
  156. return val.rankname + '类' == item;
  157. })[0];
  158. trHtml += '<td><div class="my_cell">' + rank.stunum +
  159. '</div></td><td><div class="my_cell">' + rank.sturate +
  160. '</div></td>'
  161. });
  162. goodTableTbodyHtml += '<tr>' + trHtml + '</tr>';
  163. });
  164. $(".section_2_level .goodTableHeadTr1").html(goodTableHeadTr1Html);
  165. $(".section_2_level .goodTableHeadTr2").html(goodTableHeadTr2Html);
  166. $(".section_2_level .goodTableTbody").html(goodTableTbodyHtml);
  167. }
  168. var parameter = $(".section_2_html_root .section_2_level_html_root").data("page-params");
  169. parameter = JSON.parse(parameter);
  170. var list = $.grep(parameter.djfx, function (item) {
  171. return item.ranktype == 1 && item.subjectid == 'zf';
  172. })[0].ranks;
  173. initclassLevelEcharts(list);
  174. });