pflPieChart.vue 2.8 KB

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