index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="data_body">
  3. <div style="width: 100%; height: 100%">
  4. <div id="charts_canvas" class="echart" style="width: 100%; height: 100%; "></div>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. evCourseArray: {
  12. type: Object,
  13. default: () => {}
  14. },
  15. // eva: {
  16. // type: String,
  17. // default: ''
  18. // }
  19. },
  20. data() {
  21. return {
  22. chartObj: null,
  23. ooption: {
  24. xdata: [],
  25. sdata: [],
  26. },
  27. name:['100分','90-99分','80-89分','70-79分','60-69分','0-59分'],
  28. option: {
  29. xAxis: {
  30. type: 'value',
  31. show: false,
  32. // max: 500
  33. },
  34. tooltip: {
  35. trigger: 'axis',
  36. axisPointer: {
  37. // Use axis to trigger tooltip
  38. type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
  39. }
  40. },
  41. grid: {
  42. left: '15%',
  43. right: '5%',
  44. bottom: '5%',
  45. top: '5%',
  46. },
  47. yAxis: {
  48. inverse: true,
  49. type: 'category',
  50. data: [
  51. // '三(1)班级',
  52. // '三(2)班级',
  53. // '三(3)班级',
  54. // '三(4)班级',
  55. // '三(5)班级',
  56. // '三(6)班级'
  57. ]
  58. },
  59. series: [
  60. // {
  61. // showBackground: true,
  62. // stack: 'total',
  63. // data: [
  64. // 40, 30, 40, 50, 60, 70
  65. // ],
  66. // type: 'bar'
  67. // },
  68. // {
  69. // showBackground: true,
  70. // stack: 'total',
  71. // data: [
  72. // 20, 10, 26, 51, 44, 35
  73. // ],
  74. // type: 'bar'
  75. // },
  76. // {
  77. // showBackground: true,
  78. // stack: 'total',
  79. // data: [
  80. // 11, 23, 41, 15, 23, 14
  81. // ],
  82. // type: 'bar'
  83. // },
  84. // {
  85. // showBackground: true,
  86. // stack: 'total',
  87. // data: [
  88. // 41, 21, 21, 12, 24, 34
  89. // ],
  90. // type: 'bar'
  91. // },
  92. // {
  93. // showBackground: true,
  94. // stack: 'total',
  95. // data: [
  96. // 52, 54, 53, 24, 35, 43
  97. // ],
  98. // type: 'bar'
  99. // }
  100. ]
  101. },
  102. };
  103. },
  104. methods: {
  105. setChart(option) {
  106. // 雷达图显示的标签
  107. let newPromise = new Promise((resolve) => {
  108. resolve();
  109. });
  110. //然后异步执行echarts的初始化函数
  111. newPromise.then(() => {
  112. const chartObj = this.$echarts.init(
  113. //劳动课程
  114. this.$el.querySelector("#charts_canvas")
  115. );
  116. this.option.yAxis.data = option.xdata;
  117. this.option.series = []
  118. for(var i = 0;i<this.name.length;i++){
  119. this.option.series.push(
  120. {
  121. name:this.name[i],
  122. showBackground: true,
  123. stack: 'total',
  124. data: [],
  125. type: 'bar'
  126. },
  127. );
  128. }
  129. for(var i = 0;i<option.sdata.length;i++){
  130. for(var j = 0;j<this.option.series.length;j++){
  131. this.option.series[j].data.push(option.sdata[i][j])
  132. }
  133. }
  134. console.log(this.option);
  135. // 初始化雷达图
  136. this.chartObj = chartObj;
  137. this.chartObj.setOption(this.option);
  138. });
  139. },
  140. setArray(array) {
  141. // this.setChart(array);
  142. // return
  143. this.ooption = {
  144. xdata: array.class,
  145. sdata: array.Array,
  146. }
  147. // for (var i = 0; i < array.length; i++) {
  148. // if (array[i].evid == this.eva) {
  149. // this.ooption.xdata = array[i].indicator
  150. // this.ooption.sdata = array[i].value
  151. // break;
  152. // }
  153. // }
  154. setTimeout(() => {
  155. if (!this.chartObj) {
  156. this.setChart(this.ooption);
  157. } else {
  158. this.option.yAxis.data = this.ooption.xdata;
  159. this.option.series = []
  160. for(var i = 0;i<this.name.length;i++){
  161. this.option.series.push(
  162. {
  163. name:this.name[i],
  164. showBackground: true,
  165. stack: 'total',
  166. data: [],
  167. type: 'bar'
  168. },
  169. );
  170. }
  171. for(var i = 0;i<this.ooption.sdata.length;i++){
  172. for(var j = 0;j<this.option.series.length;j++){
  173. this.option.series[j].data.push(this.ooption.sdata[i][j])
  174. }
  175. }
  176. console.log(this.option);
  177. this.chartObj.setOption(this.option);
  178. }
  179. }, 100);
  180. this.$forceUpdate();
  181. },
  182. },
  183. watch: {
  184. evCourseArray: {
  185. immediate: true,
  186. deep: true,
  187. handler(newValue, oldValue) {
  188. this.setArray(newValue)
  189. this.$forceUpdate();
  190. },
  191. },
  192. // eva: {
  193. // immediate: true,
  194. // deep: true,
  195. // handler(newValue, oldValue) {
  196. // this.setArray(this.evCourseArray)
  197. // this.$forceUpdate();
  198. // },
  199. // },
  200. },
  201. mounted() {
  202. this.setArray(this.evCourseArray)
  203. // this.setChart(this.ooption);
  204. var _this = this;
  205. window.addEventListener("resize", () => {
  206. if (_this.chartObj) {
  207. _this.chartObj.resize();
  208. }
  209. });
  210. },
  211. };
  212. </script>
  213. <style scoped>
  214. .data_body {
  215. height: 100%;
  216. /* display: flex; */
  217. position: relative;
  218. border-radius: 5px;
  219. /* border: 1px solid #eee; */
  220. margin: 0 auto;
  221. box-sizing: border-box;
  222. padding: 0;
  223. width: 95%;
  224. background: #fff;
  225. }
  226. </style>