examSummaryPie.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/component/legend";
  11. import "echarts/lib/component/legendScroll";
  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. .post(
  27. "/api/ecs_oe_admin/exam/student/statistic/by/finished?examId=" +
  28. this.examId
  29. )
  30. .then(response => {
  31. var resp = response.data;
  32. debugger;
  33. var optionData = {
  34. title: "考试人次:" + (resp.finished + resp.unFinished),
  35. legendData: [
  36. "未完成:" + resp.unFinished,
  37. "已完成:" + resp.finished
  38. ],
  39. seriesData: [
  40. { name: "未完成:" + resp.unFinished, value: resp.unFinished },
  41. { name: "已完成:" + resp.finished, value: resp.finished }
  42. ]
  43. };
  44. this.buildOptions(optionData);
  45. });
  46. },
  47. buildOptions(data) {
  48. var colors = ["#7CB5EC", "#FE8463"];
  49. this.options = {
  50. color: colors,
  51. title: {
  52. text: data.title,
  53. subtext: "",
  54. x: "left"
  55. },
  56. tooltip: {
  57. trigger: "item",
  58. formatter: "{b}人次<br/>占比:{d}%"
  59. },
  60. legend: {
  61. type: "scroll",
  62. orient: "vertical",
  63. right: 150,
  64. bottom: 100,
  65. data: data.legendData
  66. },
  67. series: [
  68. {
  69. name: "",
  70. type: "pie",
  71. radius: "50%",
  72. center: ["32%", "50%"],
  73. data: data.seriesData,
  74. itemStyle: {
  75. emphasis: {
  76. shadowBlur: 10,
  77. shadowOffsetX: 0,
  78. shadowColor: "rgba(0, 0, 0, 0.5)"
  79. }
  80. }
  81. }
  82. ]
  83. };
  84. }
  85. },
  86. watch: {
  87. examId: function(newData) {
  88. if (newData) {
  89. this.getData();
  90. }
  91. }
  92. },
  93. created() {}
  94. };
  95. </script>
  96. <style></style>