pflPieChart.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div id="pflPieChart" :style="{height:height,width:width}"/>
  3. </template>
  4. <script>
  5. export default {
  6. name: "pflPieChart",
  7. props: {
  8. pointList: {
  9. type: Array,
  10. default() {
  11. return [];
  12. }
  13. },
  14. plantName: {
  15. type: String,
  16. default: ''
  17. },
  18. width: {
  19. type: String,
  20. default: '100%'
  21. },
  22. height: {
  23. type: String,
  24. default: '490px'
  25. },
  26. },
  27. data() {
  28. return {
  29. chart: null,
  30. option: {
  31. title: {
  32. text: '排放量',
  33. left: 'center'
  34. },
  35. tooltip: {
  36. trigger: 'item',
  37. formatter: '{a} <br/>{b} : {c} ({d}%)'
  38. },
  39. legend: {
  40. orient: 'vertical',
  41. left: 'left',
  42. data: []
  43. },
  44. toolbox: {
  45. show: true,
  46. feature: {
  47. mark: {show: true},
  48. magicType: {
  49. show: true,
  50. type: ['funnel']
  51. },
  52. restore: {show: true},
  53. saveAsImage: {show: true}
  54. }
  55. },
  56. series: [
  57. {
  58. label: {
  59. formatter: '{b}: ({d}%)'
  60. },
  61. name: '排放量',
  62. type: 'pie',
  63. radius: ['40%', '60%'],
  64. selectedMode: 'single',
  65. data: [],
  66. emphasis: {
  67. label: {
  68. show: true,
  69. fontSize: '21',
  70. fontWeight: 'bold'
  71. }
  72. },
  73. }
  74. ]
  75. },
  76. }
  77. },
  78. mounted() {
  79. this.$nextTick(() => {
  80. for (let i = 0; i < this.pointList.length; i++) {
  81. if (this.plantName != '合计' && this.plantName == this.pointList[i].plantName) {
  82. this.option.legend.data[i] = this.pointList[i].pointType
  83. this.option.series[0].data[i] = {value: this.pointList[i].pfl, name: this.pointList[i].pointType}
  84. } else if (this.plantName == '合计'||this.plantName ==''){
  85. this.option.legend.data[i] = this.pointList[i].pointType
  86. this.option.series[0].data[i] = {value: this.pointList[i].pfl, name: this.pointList[i].pointType}
  87. }
  88. }
  89. this.initChart();
  90. })
  91. },
  92. methods: {
  93. initChart() {
  94. // 基于准备好的dom,初始化echarts实例
  95. this.chart = this.echarts.init(document.getElementById('pflPieChart'))
  96. this.chart.setOption(this.option)
  97. },
  98. }
  99. }
  100. </script>
  101. <style scoped>
  102. </style>