PieChart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: Object,
  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. // console.log(data)
  61. this.chart.setOption({
  62. graphic:{
  63. type: 'text',
  64. left: 'center',
  65. top: 'center',
  66. style:{
  67. text:'本周与上周\n核酸人数',
  68. textAlign:"center",
  69. fill:"#333",
  70. fontSize:14,
  71. },
  72. },
  73. tooltip: {
  74. trigger: 'item',
  75. },
  76. color:['#18A6E2', '#02DB80'],
  77. legend: {
  78. show:false,
  79. // bottom: 10,
  80. // left: 'center',
  81. },
  82. series: [
  83. {
  84. name: '',
  85. type: 'pie',
  86. radius: ['40%', '70%'],
  87. avoidLabelOverlap: false,
  88. center: ['50%', '50%'],
  89. itemStyle: {
  90. borderRadius: 10,
  91. borderColor: '#fff',
  92. borderWidth: 2
  93. },
  94. label: {
  95. show: false,
  96. position: 'center'
  97. },
  98. // emphasis: {
  99. // label: {
  100. // show: true,
  101. // fontSize: '18',
  102. // fontWeight: '400',
  103. // color:"#333"
  104. // }
  105. // },
  106. labelLine: {
  107. show: false
  108. },
  109. // data:data,
  110. data: [
  111. { value: data.indexDataLastWeek, name: '上周核酸人数' },
  112. { value: data.indexDataWeek, name: '本周核酸人数' }
  113. ]
  114. }
  115. ]
  116. })
  117. }
  118. }
  119. }
  120. </script>