index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="data_body">
  3. <div style="width: 100%; height: 100%">
  4. <div
  5. id="charts_canvas"
  6. class="echart"
  7. style="width: 100%; height: 100%"
  8. ></div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. EworksNumArray: {
  16. type: Array,
  17. },
  18. },
  19. data() {
  20. return {
  21. chartObj: null,
  22. ooption: {
  23. xdata: [],
  24. data: [],
  25. },
  26. option: {
  27. // title: {
  28. // text: '在线时长',
  29. // textStyle: {
  30. // fontSize: 12,
  31. // },
  32. // padding: [5, 0, 0, 10]
  33. // },
  34. tooltip: {
  35. trigger: "axis",
  36. axisPointer: {
  37. type: "shadow",
  38. },
  39. },
  40. dataZoom: [
  41. {
  42. // start: 50,
  43. type: 'inside',
  44. xAxisIndex: 0
  45. },
  46. {
  47. type: 'slider',
  48. xAxisIndex: 0
  49. }
  50. ],
  51. grid: {
  52. top: '5%',
  53. left: '5%',
  54. right: '10%',
  55. bottom: '15%',
  56. containLabel: true
  57. },
  58. xAxis: {
  59. type: 'category',
  60. data: [],
  61. // data: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
  62. },
  63. yAxis: {
  64. type: 'value',
  65. },
  66. series: [
  67. {
  68. name: "作业数量",
  69. type: 'bar',
  70. // data: [180, 50, 70, 90, 100, 130],
  71. data: [],
  72. itemStyle: {
  73. normal: {
  74. color: function (params) {
  75. return "#106bff";
  76. },
  77. },
  78. },
  79. }
  80. ]
  81. },
  82. };
  83. },
  84. methods: {
  85. setChart(option) {
  86. // 雷达图显示的标签
  87. let newPromise = new Promise((resolve) => {
  88. resolve();
  89. });
  90. //然后异步执行echarts的初始化函数
  91. newPromise.then(() => {
  92. const chartObj = this.$echarts.init(
  93. //劳动课程
  94. this.$el.querySelector("#charts_canvas")
  95. );
  96. this.option.xAxis.data = option.xdata;
  97. this.option.series[0].data = option.data;
  98. // 初始化雷达图
  99. this.chartObj = chartObj;
  100. this.chartObj.setOption(this.option);
  101. });
  102. },
  103. setArray(Array) {
  104. this.ooption = {
  105. xdata: [],
  106. data: [],
  107. }
  108. let _array = Array
  109. for (var i = 0; i < _array.length; i++) {
  110. this.ooption.xdata.push(_array[i].name)
  111. this.ooption.data.push(_array[i].works)
  112. }
  113. if (!this.chartObj) {
  114. this.setChart(this.ooption);
  115. } else {
  116. this.option.xAxis.data = this.ooption.xdata;
  117. this.option.series[0].data = this.ooption.data;
  118. this.chartObj.setOption(this.option);
  119. }
  120. }
  121. },
  122. watch: {
  123. EworksNumArray: {
  124. immediate: true,
  125. deep: true,
  126. handler(newValue, oldValue) {
  127. this.setArray(newValue)
  128. this.$forceUpdate();
  129. },
  130. },
  131. },
  132. mounted() {
  133. this.setArray(this.EworksNumArray)
  134. var _this = this;
  135. window.addEventListener("resize", () => {
  136. if (_this.chartObj) {
  137. _this.chartObj.resize();
  138. }
  139. });
  140. },
  141. };
  142. </script>
  143. <style scoped>
  144. .data_body {
  145. height: 100%;
  146. position: relative;
  147. border-radius: 5px;
  148. margin: 0 auto;
  149. box-sizing: border-box;
  150. padding: 0;
  151. width: 95%;
  152. /* background: #fff; */
  153. }
  154. </style>