index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. EscoreArray2: {
  12. type: Array,
  13. },
  14. },
  15. data() {
  16. return {
  17. chartObj: null,
  18. ooption: {
  19. xdata: [],
  20. sdata: [],
  21. },
  22. option: {
  23. xAxis: {
  24. // data: ['一年级一班', '一年级二班', '一年级三班', '一年级四班', '一年级五班', '一年级六班', '一年级七班']
  25. data: []
  26. },
  27. tooltip: {
  28. formatter: function (params, ticket, callback) {
  29. return `${params.marker + params.name}</br>最高分:${params.value[2]}</br>最低分:${params.value[1]}`;
  30. }
  31. },
  32. dataZoom: [
  33. {
  34. // start: 50,
  35. type: 'inside',
  36. },
  37. {
  38. type: 'slider',
  39. }
  40. ],
  41. yAxis: {},
  42. grid: {
  43. top: '5%',
  44. left: '0%',
  45. right: '0%',
  46. bottom: '13%',
  47. containLabel: true
  48. },
  49. series: [
  50. {
  51. type: 'candlestick',
  52. data: [
  53. // [70, 80, 70, 80],
  54. // [60, 90, 60, 90],
  55. // [50, 80, 50, 80],
  56. // [78, 88, 78, 88],
  57. // [85, 98, 85, 98],
  58. // [75, 95, 75, 95],
  59. // [65, 100, 65, 100],
  60. // [55, 99, 55, 99]
  61. ],
  62. itemStyle: {
  63. color: '#17C469',
  64. borderColor: null
  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.xAxis.data = option.xdata;
  84. this.option.series[0].data = option.sdata;
  85. chartObj.off('click')
  86. let _this = this
  87. chartObj.on('click', function (param) {
  88. console.log(param); //X轴的值
  89. _this.$emit('openDataClass', param.dataIndex)
  90. });
  91. // 初始化雷达图
  92. this.chartObj = chartObj;
  93. this.chartObj.setOption(this.option);
  94. });
  95. },
  96. setArray(Array) {
  97. this.ooption = {
  98. xdata: [],
  99. sdata: [],
  100. }
  101. let _array = Array
  102. for (var i = 0; i < _array.length; i++) {
  103. this.ooption.xdata.push(_array[i].name)
  104. this.ooption.sdata.push([_array[i].min, _array[i].max, _array[i].min, _array[i].max])
  105. }
  106. if (!this.chartObj) {
  107. this.setChart(this.ooption);
  108. } else {
  109. this.option.xAxis.data = this.ooption.xdata;
  110. this.option.series[0].data = this.ooption.sdata;
  111. this.chartObj.setOption(this.option);
  112. }
  113. }
  114. },
  115. watch: {
  116. EscoreArray2: {
  117. immediate: true,
  118. deep: true,
  119. handler(newValue, oldValue) {
  120. this.setArray(newValue)
  121. this.$forceUpdate();
  122. },
  123. },
  124. },
  125. mounted() {
  126. this.setArray(this.EscoreArray2)
  127. var _this = this;
  128. window.addEventListener("resize", () => {
  129. if (_this.chartObj) {
  130. _this.chartObj.resize();
  131. }
  132. });
  133. },
  134. };
  135. </script>
  136. <style scoped>
  137. .data_body {
  138. height: 100%;
  139. /* display: flex; */
  140. position: relative;
  141. border-radius: 5px;
  142. /* border: 1px solid #eee; */
  143. margin: 0 auto;
  144. box-sizing: border-box;
  145. padding: 0;
  146. width: 95%;
  147. background: #fff;
  148. }
  149. </style>