PieChart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import resize from '../mixins/resize'
  8. export default {
  9. mixins: [resize],
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. width: {
  16. type: String,
  17. default: '100%'
  18. },
  19. height: {
  20. type: String,
  21. default: '200px'
  22. },
  23. chartData: {
  24. type: Array,
  25. required: true
  26. }
  27. },
  28. watch: {
  29. chartData: {
  30. deep: true,
  31. handler(val) {
  32. this.setOptions(val)
  33. }
  34. }
  35. },
  36. data() {
  37. return {
  38. chart: null
  39. }
  40. },
  41. mounted() {
  42. this.$nextTick(() => {
  43. this.initChart()
  44. })
  45. },
  46. beforeDestroy() {
  47. if (!this.chart) {
  48. return
  49. }
  50. this.chart.dispose()
  51. this.chart = null
  52. },
  53. methods: {
  54. initChart() {
  55. this.chart = echarts.init(this.$el, 'macarons');
  56. this.chart = echarts.init(this.$el, 'macarons')
  57. this.setOptions(this.chartData)
  58. },
  59. setOptions(data) {
  60. this.chart.setOption({
  61. graphic:{
  62. type: 'text',
  63. left: 'center',
  64. top: 'center',
  65. style:{
  66. text:'本周与上周\n核酸人数',
  67. textAlign:"center",
  68. fill:"#333",
  69. fontSize:14,
  70. },
  71. },
  72. tooltip: {
  73. trigger: 'item',
  74. },
  75. color:['#18A6E2', '#02DB80'],
  76. legend: {
  77. show:false,
  78. // bottom: 10,
  79. // left: 'center',
  80. },
  81. series: [
  82. {
  83. name: '',
  84. type: 'pie',
  85. radius: ['40%', '70%'],
  86. avoidLabelOverlap: false,
  87. center: ['50%', '50%'],
  88. itemStyle: {
  89. borderRadius: 10,
  90. borderColor: '#fff',
  91. borderWidth: 2
  92. },
  93. label: {
  94. show: false,
  95. position: 'center'
  96. },
  97. // emphasis: {
  98. // label: {
  99. // show: true,
  100. // fontSize: '18',
  101. // fontWeight: '400',
  102. // color:"#333"
  103. // }
  104. // },
  105. labelLine: {
  106. show: false
  107. },
  108. // data:data,
  109. data: [
  110. { value: 6, name: '上周核酸人数' },
  111. { value: 4, name: '本周核酸人数' }
  112. ]
  113. }
  114. ]
  115. })
  116. }
  117. }
  118. }
  119. </script>