ProgPie.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div id="mark-prog-pie"></div>
  3. </template>
  4. <script>
  5. import elementResizeDetectorMaker from "element-resize-detector"
  6. export default {
  7. props: {
  8. count: {
  9. type: Array,
  10. default: () => {
  11. return [0, 0, 0]
  12. }
  13. }
  14. },
  15. data() {
  16. return {
  17. techScoreGau: undefined,
  18. option: {
  19. // title: {
  20. // text: '阅卷进度',
  21. // left: 'center',
  22. // textStyle: {
  23. // color: '#ddd',
  24. // fontSize: 12
  25. // }
  26. // },
  27. tooltip: {
  28. trigger: 'item',
  29. // formatter: '{a} <br/>{b} : {c} ({d}%)'
  30. formatter: '{b} : {c} ({d}%)'
  31. },
  32. legend: {
  33. top: 10,
  34. itemWidth: 10,
  35. itemHeight: 10,
  36. left: 'center',
  37. data: ['已阅', '进行中', '未阅'],
  38. textStyle: {
  39. color: '#ddd',
  40. fontSize: 11,
  41. },
  42. },
  43. series: [
  44. {
  45. type: 'pie',
  46. radius: '75%',
  47. center: ['50%', '60%'],
  48. selectedMode: 'single',
  49. data: [
  50. {
  51. value: 0,
  52. name: '已阅',
  53. itemStyle: {
  54. color: "#9ff080"
  55. },
  56. },
  57. {
  58. value: 0,
  59. name: '进行中',
  60. itemStyle: {
  61. color: "#5c7bd9"
  62. },
  63. },
  64. {
  65. value: 0,
  66. name: '未阅',
  67. itemStyle: {
  68. color: "#ffdc60"
  69. },
  70. }
  71. ],
  72. label: {
  73. show: false
  74. },
  75. emphasis: {
  76. itemStyle: {
  77. shadowBlur: 10,
  78. shadowOffsetX: 0,
  79. shadowColor: 'rgba(0, 0, 0, 0.5)'
  80. }
  81. }
  82. }
  83. ]
  84. }
  85. }
  86. },
  87. mounted() {
  88. this.techScoreGau = this.$echarts.init(document.getElementById('mark-prog-pie'))
  89. this.techScoreGau.setOption(this.option)
  90. this.erd = elementResizeDetectorMaker()
  91. this.erd.listenTo(document.getElementById("mark-prog-pie"), () => {
  92. this.$nextTick(() => {
  93. //监听到事件后执行的业务逻辑
  94. this.techScoreGau.resize()
  95. })
  96. })
  97. },
  98. watch: {
  99. count: {
  100. handler(n, o) {
  101. this.count.forEach((item, index) => {
  102. console.log(item, index)
  103. this.option.series[0].data[index].value = item
  104. })
  105. if (!this.techScoreGau) {
  106. this.$nextTick(() => {
  107. this.techScoreGau = this.$echarts.init(document.getElementById('mark-prog-pie'))
  108. this.techScoreGau.setOption(this.option)
  109. })
  110. } else {
  111. this.techScoreGau.setOption(this.option)
  112. }
  113. },
  114. immediate: true,
  115. deep: true
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="less" scoped>
  121. #mark-prog-pie {
  122. width: 400px;
  123. height: 200px;
  124. }
  125. </style>
  126. <style>
  127. </style>