ring.vue 4.7 KB

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