ring.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="main-chart" ref="main" id="main" style="width: 520rpx;height:230px;background-color: #fff; margin: 0 auto;"></div>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. export default {
  7. props: {
  8. Chart: {
  9. type: Array,
  10. },
  11. },
  12. watch: {
  13. dataList(newVal, oldVal) {
  14. console.log(newVal);
  15. if(newVal.length==0){
  16. return
  17. }
  18. if (newVal && newVal.xAxis.length != 0) {
  19. let xTime = []
  20. newVal.xAxis.forEach(ele=>{
  21. xTime.push(...ele.split(' ',1))
  22. })
  23. if (xTime.length>0){
  24. newVal.xAxis = xTime
  25. }
  26. this.init()
  27. } else {
  28. // this.dataList = {
  29. // xAxis: ['3/25', '3/26', '3/27', '3/28', '3/29', '3/30', '3/31'],
  30. // classData: [],
  31. // studentData: []
  32. // }
  33. }
  34. },
  35. 'dataList.xAxis'(newVal, oldVal) {
  36. console.log('abc', newVal.length);
  37. if (newVal.length == 1 || !newVal) {
  38. this.echartsType = 'bar'
  39. this.init()
  40. } else {
  41. this.echartsType = 'line'
  42. }
  43. },
  44. // start(newVal){
  45. // if (newVal) {
  46. // this.init()
  47. // }
  48. // }
  49. },
  50. data() {
  51. return {
  52. index: 0,
  53. timer: null,
  54. echartsType: 'line'
  55. }
  56. },
  57. mounted() {
  58. this.init();
  59. // window.addEventListener('click',()=>{
  60. // console.log(333);
  61. // })
  62. // this.set()
  63. },
  64. destroyed() {
  65. clearInterval(this.timer)
  66. this.timer = null
  67. },
  68. methods: {
  69. filter() {
  70. if (this.dataList.classData?.length == 0 && this.dataList.studentData?.length == 0) {
  71. return 200
  72. }
  73. if (this.dataList && this.dataList.classData && this.dataList?.classData.length > 0) {
  74. this.index = this.dataList.xAxis.length - 1
  75. return Math.max(...this.dataList?.classData, ...this.dataList?.studentData).toFixed(1)
  76. }
  77. },
  78. init() {
  79. var chartDom = this.$refs.main;
  80. var myChart = echarts.init(chartDom);
  81. var option;
  82. let that = this
  83. option = {
  84. title: {
  85. text: '',
  86. left: 'center',
  87. top: 'center'
  88. },
  89. color: ['rgba(0,199,119,0.38)', '#FAE380', '#F1A2A0', '#ef6567', '#f9c956', '#75bedc'],
  90. series: [
  91. {
  92. type: 'pie',
  93. startAngle: 180, //起始角度
  94. data: this.Chart,
  95. itemStyle: {
  96. normal: {
  97. borderWidth: 2,
  98. borderColor: '#ffffff',
  99. },
  100. },
  101. radius: ['40%', '60%']
  102. }
  103. ]
  104. };
  105. option && myChart.setOption(option);
  106. // 实现自动播放tooltip的方法
  107. // var index = 0; //播放所在下标
  108. // clearInterval(this.timer)
  109. // this.timer = setInterval(function () {
  110. myChart.dispatchAction({
  111. type: 'showTip',
  112. seriesIndex: 0,
  113. dataIndex: 0
  114. });
  115. // that.index = index
  116. // myChart.setOption(option);
  117. // index++;
  118. // if (index > 7) {
  119. // index = 0;
  120. // }
  121. // }, 2000);
  122. // myChart.getZr().off('click');
  123. // myChart.getZr().on('click', function(params) {
  124. // let pointInPixel= [params.offsetX, params.offsetY];
  125. // if (myChart.containPixel('grid',pointInPixel)) {
  126. // let indexFlg= myChart.convertFromPixel({seriesIndex:0},[params.offsetX, params.offsetY])[0]; //获取所点击的点的索引
  127. // console.log(indexFlg);
  128. // //可根据索引来开发相对应业务逻辑
  129. // }
  130. // console.log(params);
  131. // that.index = params.dataIndex
  132. // // option[]
  133. // myChart.setOption(option);
  134. // // console.log(option)
  135. // });
  136. console.log(echarts)
  137. // that.echarts.dispatchAction({
  138. // type:'showTip',
  139. // seriesIndex:0,
  140. // dataIndex:that.index
  141. // })
  142. },
  143. },
  144. }
  145. </script>
  146. <style scoped>
  147. .main-chart div{
  148. z-index: 0 !important;
  149. }
  150. </style>