examSummaryLine.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div><v-chart :options="options" /></div>
  3. </template>
  4. <script>
  5. import ECharts from "vue-echarts/components/ECharts";
  6. import "echarts/lib/chart/pie";
  7. import "echarts/lib/component/polar";
  8. import "echarts/lib/component/tooltip";
  9. import "echarts/lib/component/title";
  10. import "echarts/lib/chart/bar";
  11. import "echarts/lib/chart/line";
  12. export default {
  13. props: ["examId"],
  14. components: {
  15. "v-chart": ECharts
  16. },
  17. data() {
  18. return { options: {} };
  19. },
  20. methods: {
  21. getData() {
  22. if (!this.examId) {
  23. return;
  24. }
  25. this.$http
  26. .get(
  27. "/api/ecs_oe_admin/exam/student/courseProgress/list?examId=" +
  28. this.examId +
  29. "&isForChart=true"
  30. )
  31. .then(response => {
  32. debugger;
  33. var resp = response.data;
  34. resp.sort(function(a, b) {
  35. if (b["completedProportion"] != a["completedProportion"]) {
  36. return b["completedProportion"] - a["completedProportion"];
  37. } else if (b["allNum"] != a["allNum"]) {
  38. return b["allNum"] - a["allNum"];
  39. } else {
  40. return b["completedNum"] - a["completedNum"];
  41. }
  42. });
  43. var campusCount = 5;
  44. var courseProgressDataList = [];
  45. //找出5个完成比例最高的
  46. if (resp.length >= campusCount) {
  47. courseProgressDataList = resp.slice(0, campusCount);
  48. } else {
  49. courseProgressDataList = resp;
  50. }
  51. var xAxisData = [];
  52. var seriesBar = {
  53. name: "计划数",
  54. type: "bar",
  55. data: []
  56. };
  57. var seriesLine1 = {
  58. name: "完成数",
  59. type: "line",
  60. data: []
  61. };
  62. var seriesLine2 = {
  63. name: "完成比(%)",
  64. type: "line",
  65. data: []
  66. };
  67. var yAxis = { maxScale1: 0, maxScale2: 0 };
  68. for (var i = 0; i < courseProgressDataList.length; i++) {
  69. xAxisData.push(courseProgressDataList[i].courseName);
  70. seriesBar.data.push(courseProgressDataList[i].allNum);
  71. seriesLine1.data.push(courseProgressDataList[i].completedNum);
  72. seriesLine2.data.push(
  73. courseProgressDataList[i].completedProportion
  74. );
  75. yAxis.maxScale1 = courseProgressDataList[0].allNum;
  76. yAxis.maxScale2 = courseProgressDataList[0].completedProportion;
  77. }
  78. var optionData = {
  79. legendData: ["计划数", "完成数", "完成比(%)"],
  80. xAxis: { data: xAxisData },
  81. series: [seriesBar, seriesLine1, seriesLine2],
  82. yAxis
  83. };
  84. this.buildOptions(optionData);
  85. });
  86. },
  87. buildOptions(optionData) {
  88. var colors = ["#FE8463", "#66CCFF", "#675bba"];
  89. this.options = {
  90. color: colors,
  91. tooltip: {
  92. trigger: "axis",
  93. axisPointer: {
  94. type: "cross",
  95. crossStyle: {
  96. color: "#999"
  97. }
  98. }
  99. },
  100. toolbox: {
  101. feature: {
  102. dataView: { show: true, readOnly: false },
  103. magicType: { show: true, type: ["line", "bar"] },
  104. restore: { show: true },
  105. saveAsImage: { show: true }
  106. }
  107. },
  108. legend: {
  109. data: optionData.legendData
  110. },
  111. xAxis: [
  112. {
  113. type: "category",
  114. data: optionData.xAxis.data,
  115. axisPointer: {
  116. type: "shadow"
  117. }
  118. }
  119. ],
  120. yAxis: [
  121. {
  122. type: "value",
  123. name: "人次",
  124. min: 0,
  125. max: optionData.yAxis.maxScale1,
  126. interval: 50,
  127. axisLabel: {
  128. formatter: "{value} "
  129. }
  130. },
  131. {
  132. type: "value",
  133. name: "完成比例",
  134. min: 0,
  135. max: optionData.yAxis.maxScale2,
  136. interval: 20,
  137. axisLabel: {
  138. formatter: "{value} %"
  139. }
  140. }
  141. ],
  142. series: optionData.series
  143. };
  144. }
  145. },
  146. watch: {
  147. examId: function(newData) {
  148. if (newData) {
  149. this.getData();
  150. }
  151. }
  152. },
  153. created() {}
  154. };
  155. </script>
  156. <style></style>