index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="data_body">
  3. <!-- v-if="this.ooption.xdata.length" -->
  4. <div style="width: 100%; height: 100%">
  5. <div id="charts_canvas" class="echart" style="width: 100%; height: 100%; "></div>
  6. </div>
  7. <!-- <div style="width: 100%; height: 100%;display: flex;align-items: center;justify-content: center;"
  8. v-show="!this.ooption.xdata.length">暂无数据</div> -->
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. props: {
  14. evCourseArray: {
  15. type: Array,
  16. default: []
  17. },
  18. eva: {
  19. type: String,
  20. default: ''
  21. }
  22. },
  23. data() {
  24. return {
  25. chartObj: null,
  26. ooption: {
  27. xdata: [],
  28. sdata: [],
  29. },
  30. option: {
  31. tooltip: {},
  32. radar: {
  33. axisName: {
  34. color: "#000"
  35. },
  36. // shape: 'circle',
  37. indicator: [
  38. // { name: '目标一', max: 5 },
  39. // { name: '目标二', max: 5 },
  40. // { name: '目标三', max: 5 },
  41. // { name: '目标四', max: 5 },
  42. // { name: '目标五', max: 5 }
  43. ]
  44. },
  45. series: [
  46. {
  47. name: '学生综合评价',
  48. type: 'radar',
  49. data: [
  50. {
  51. areaStyle: {
  52. opacity: 0.2,
  53. color: '#0061FF'
  54. },
  55. itemStyle: {
  56. color: '#0061FF',
  57. lineStyle: {
  58. color: '#0061FF'
  59. }
  60. },
  61. // 5, 4, 3, 5, 5, 2
  62. value: [],
  63. name: ''
  64. }
  65. ]
  66. }
  67. ]
  68. },
  69. };
  70. },
  71. methods: {
  72. setChart(option) {
  73. // 雷达图显示的标签
  74. let newPromise = new Promise((resolve) => {
  75. resolve();
  76. });
  77. //然后异步执行echarts的初始化函数
  78. newPromise.then(() => {
  79. const chartObj = this.$echarts.init(
  80. //劳动课程
  81. this.$el.querySelector("#charts_canvas")
  82. );
  83. // this.option.radar.indicator = option.xdata;
  84. // this.option.series[0].data[0].value = option.sdata;
  85. this.option.radar.indicator = [
  86. { name: '成茁小先生', max: 5 },
  87. { name: '成行小先生', max: 5 },
  88. { name: '成智小先生', max: 5 },
  89. { name: '成德小先生', max: 5 },
  90. { name: '成彩小先生', max: 5 }
  91. ]
  92. this.option.series[0].data[0].value = [1,1,3,5,5];
  93. // 初始化雷达图
  94. this.chartObj = chartObj;
  95. this.chartObj.setOption(this.option);
  96. });
  97. },
  98. setArray(array) {
  99. this.setChart(array);
  100. return
  101. this.ooption = {
  102. xdata: [],
  103. sdata: [],
  104. }
  105. for (var i = 0; i < array.length; i++) {
  106. if (array[i].evid == this.eva) {
  107. this.ooption.xdata = array[i].indicator
  108. this.ooption.sdata = array[i].value
  109. break;
  110. }
  111. }
  112. setTimeout(() => {
  113. // if (!this.chartObj) {
  114. this.setChart(this.ooption);
  115. // } else {
  116. // this.option.radar.indicator = this.ooption.xdata;
  117. // this.option.series[0].data[0].value = this.ooption.sdata;
  118. // this.chartObj.setOption(this.option);
  119. // }
  120. }, 100);
  121. this.$forceUpdate();
  122. },
  123. },
  124. watch: {
  125. evCourseArray: {
  126. immediate: true,
  127. deep: true,
  128. handler(newValue, oldValue) {
  129. this.setArray(newValue)
  130. this.$forceUpdate();
  131. },
  132. },
  133. eva: {
  134. immediate: true,
  135. deep: true,
  136. handler(newValue, oldValue) {
  137. this.setArray(this.evCourseArray)
  138. this.$forceUpdate();
  139. },
  140. },
  141. },
  142. mounted() {
  143. this.setArray(this.evCourseArray)
  144. // this.setChart(this.ooption);
  145. var _this = this;
  146. window.addEventListener("resize", () => {
  147. if (_this.chartObj) {
  148. _this.chartObj.resize();
  149. }
  150. });
  151. },
  152. };
  153. </script>
  154. <style scoped>
  155. .data_body {
  156. height: 100%;
  157. /* display: flex; */
  158. position: relative;
  159. border-radius: 5px;
  160. /* border: 1px solid #eee; */
  161. margin: 0 auto;
  162. box-sizing: border-box;
  163. padding: 0;
  164. width: 95%;
  165. background: #fff;
  166. }
  167. </style>