progressCircleChart.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div ref="chart" style="width: 100%; height: 100%;">
  3. </div>
  4. </template>
  5. <script setup>
  6. import * as echarts from 'echarts'
  7. import { defineProps, onBeforeUnmount, onMounted, ref, watch } from 'vue'
  8. const props = defineProps({
  9. value: {}
  10. })
  11. const chart = ref()
  12. let chartObj
  13. onMounted(() => {
  14. initChart()
  15. setOption()
  16. })
  17. onBeforeUnmount(() => {
  18. chartObj && chartObj.dispose()
  19. })
  20. function initChart() {
  21. chartObj = echarts.init(chart.value)
  22. }
  23. function setOption() {
  24. const value = +props.value.replace('%', '')
  25. chartObj.setOption({
  26. tooltip: {
  27. trigger: 'item'
  28. },
  29. legend: {
  30. selectedMode: false //取消图例上的点击事件
  31. },
  32. series: {
  33. type: 'pie',
  34. silent: true,
  35. emphasis: {
  36. show: false
  37. },
  38. label: {
  39. show: false
  40. },
  41. radius: ['55%', '65%'],
  42. data: [
  43. {
  44. value,
  45. itemStyle: {
  46. color: {
  47. type: 'linear',
  48. x: 0,
  49. y: 0,
  50. x2: 0,
  51. y2: 1,
  52. colorStops: [{
  53. offset: 1, color: '#0B5BDD' // 0% 处的颜色
  54. }, {
  55. offset: 0, color: '#35A5FF' // 100% 处的颜色
  56. }],
  57. },
  58. }
  59. }, {
  60. value: 100-value,
  61. itemStyle: {
  62. color: '#00000000'
  63. }
  64. }
  65. ]
  66. }
  67. })
  68. }
  69. watch(() => props.value, setOption)
  70. </script>