echartsPie.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div :class="className" style="height: 160px;width:160px" />
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. export default {
  7. name: 'echartsPie',
  8. props: {
  9. className: {
  10. type: String,
  11. default: 'chart'
  12. }
  13. },
  14. data() {
  15. return {
  16. chart: null
  17. }
  18. },
  19. mounted() {
  20. this.$nextTick(() => {
  21. this.initChart()
  22. })
  23. },
  24. beforeDestroy() {
  25. if (!this.chart) {
  26. return
  27. }
  28. this.chart.dispose()
  29. this.chart = null
  30. },
  31. methods: {
  32. initChart() {
  33. this.chart = echarts.init(this.$el, 'macarons')
  34. this.chart.setOption({
  35. tooltip:{
  36. show:false,
  37. },
  38. hoverAnimation: false,
  39. title: {
  40. text: '',
  41. subtext: '',
  42. x: 'center',
  43. y: 'center',
  44. top: '36%',
  45. textStyle: {
  46. fontSize: 12,
  47. },
  48. subtextStyle: {
  49. fontSize: 12,
  50. color: '#333',
  51. fontWeight: 700
  52. }
  53. },
  54. animation: false,
  55. series: [
  56. {
  57. type: 'pie',
  58. center: [45,45],
  59. radius: ['48%', '55%'],
  60. label: {
  61. position: 'center',
  62. show: true,
  63. color: '#1E7CE8',
  64. formatter: ['{a|60}%','{b|实际用水量}'].join('\n'),
  65. rich: {
  66. a: {
  67. fontSize:'22px',
  68. },
  69. b:{
  70. color: '#333333',
  71. fontSize: '12px',
  72. padding:[10,0,0,0]
  73. }
  74. },
  75. textStyle: {
  76. align: "center",
  77. color: '#333',
  78. fontSize: 12,
  79. baseline: "middle"
  80. },
  81. lineHeight: 16,
  82. fontSize: 12,
  83. },
  84. itemStyle: {
  85. color: '#c23531',
  86. shadowBlur: 200,
  87. shadowColor: 'rgba(0, 0, 0, 0)'
  88. },
  89. emphasis: {
  90. scale: false,
  91. selectorLabel:{
  92. show: false
  93. },
  94. itemStyle: {
  95. color: 'inherit'
  96. },
  97. textStyle: {
  98. fontSize: '30',
  99. fontWeight: 'bold'
  100. },
  101. label: {
  102. show: false,
  103. fontWeight: 'bold'
  104. },
  105. disable:false, //是否关闭扇区高亮效果
  106. scale:false, //扇区是否缩放
  107. scaleSize:0,
  108. },
  109. labelLine: {
  110. show: false
  111. },
  112. data: [
  113. { value: 1048, name: 'Direct',itemStyle:{color: '#1890FF'} },
  114. { value: 1048, name: 'Direct2',itemStyle:{color: '#D9D9D9'} }
  115. ]
  116. }
  117. ]
  118. })
  119. this.chart.on('mouseover',e=>{
  120. let op = this.chart.getOption()
  121. this.chart.dispatchAction({
  122. type: 'downplay',
  123. animation: false,
  124. seriesIndex: 0,
  125. dataIndex: e.dataIndex,
  126. color: e.color
  127. })
  128. this.chart.setOption(op, true)
  129. })
  130. }
  131. }
  132. }
  133. </script>