pieChart.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div shadow="never" class="homeBoxCard">
  3. <div class="height300" id="pieChart" ref="pieChart" />
  4. </div>
  5. </template>
  6. <script setup>
  7. import { defineComponent, onMounted, watch, ref } from 'vue'
  8. // import { useStore } from 'vuex'
  9. import * as echarts from 'echarts'
  10. // var total_datas = 0
  11. // for (var i = 0; i < echartData.length; i++) {
  12. // total_datas += Number(echartData[i].value)
  13. // console.log(typeof echartData[i].value)
  14. // }
  15. const props = defineProps({
  16. getTableData: Object,
  17. })
  18. let pieChart = ref(null)
  19. // 读取数据 func
  20. const getData = async () => {}
  21. function echarts2() {
  22. let myChart = echarts.init(pieChart.value)
  23. // 绘制图表
  24. myChart.setOption({
  25. title: [
  26. {
  27. text: 1,
  28. subtext: '共计回路',
  29. textStyle: {
  30. fontSize: 24,
  31. color: 'black',
  32. },
  33. subtextStyle: {
  34. fontSize: 16,
  35. color: 'black',
  36. },
  37. textAlign: 'center',
  38. left: '49%',
  39. top: '40%',
  40. },
  41. ],
  42. tooltip: {
  43. trigger: 'item',
  44. formatter: function (parms) {
  45. var str =
  46. '</br>' + parms.marker + '' + parms.data.legendname + '</br>'
  47. // +
  48. // '数量:' +
  49. // parms.data.value +
  50. // '</br>' +
  51. // '占比:' +
  52. // parms.percent +
  53. // '%'
  54. return str
  55. },
  56. },
  57. legend: {
  58. type: 'scroll',
  59. orient: 'horizontal',
  60. bottom: '0%',
  61. align: 'left',
  62. selectedMode: false, //取消图例上的点击事件
  63. // top:'middle',
  64. textStyle: {
  65. color: '#8C8C8C',
  66. },
  67. height: 250,
  68. },
  69. series: [
  70. {
  71. // name: '标题',
  72. type: 'pie',
  73. center: ['50%', '50%'],
  74. radius: ['37%', '55%'],
  75. clockwise: false, //饼图的扇区是否是顺时针排布
  76. avoidLabelOverlap: false,
  77. label: {
  78. show: false,
  79. },
  80. labelLine: {
  81. show: false,
  82. },
  83. data: [
  84. {
  85. value: props.getTableData.score >= 80 ? 1 : 0,
  86. legendname: '优秀',
  87. name: '优秀',
  88. itemStyle: { color: '#40ABFE' },
  89. },
  90. {
  91. value: props.getTableData.score >= 60 ? 1 : 0,
  92. legendname: '合格',
  93. name: '合格',
  94. itemStyle: { color: '#EEAA3F' },
  95. },
  96. {
  97. value: props.getTableData.score < 60 ? 1 : 0,
  98. legendname: '不合格',
  99. name: '不合格',
  100. itemStyle: { color: '#FF2222' },
  101. },
  102. ],
  103. },
  104. ],
  105. })
  106. window.addEventListener('resize', () => {
  107. myChart.resize()
  108. })
  109. }
  110. const writeValue = (val) => {
  111. val
  112. getData()
  113. echarts2()
  114. }
  115. //监听变化
  116. watch(
  117. () => props.getTableData,
  118. (newVal, oldVal, clear) => {
  119. // 执行异步任务,并得到关闭异步任务的 id
  120. // console.log(newVal)
  121. let id = writeValue(newVal, oldVal)
  122. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  123. clear(() => clearTimeout(id))
  124. },
  125. { lazy: true }
  126. )
  127. onMounted(() => {
  128. getData()
  129. echarts2()
  130. })
  131. </script>
  132. <style lang="scss" scoped>
  133. .homeBoxCard {
  134. margin-bottom: 24px;
  135. :deep(.el-card__header) {
  136. padding-left: 12px;
  137. padding-right: 12px;
  138. }
  139. :deep(.el-card__body) {
  140. padding: 12px;
  141. font-size: 14px;
  142. line-height: 1.5715;
  143. }
  144. :deep(.el-divider) {
  145. margin: 8px 0;
  146. }
  147. .num {
  148. font-size: 30px;
  149. color: #515a6e;
  150. }
  151. .height300 {
  152. height: 300px;
  153. }
  154. }
  155. </style>