carbonPvEmissionChart.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script>
  2. import apiCarbonOverview from "@/api/carbon/apiCarbonOverview";
  3. import apiCarbonCar from "@/api/carbon/apiCarbonCar";
  4. import apiCarbonPv from "@/api/carbon/apiCarbonPv";
  5. export default {
  6. data() {
  7. return {
  8. seriesData: {
  9. name: '',
  10. data: [],
  11. type: 'line',
  12. smooth: true,
  13. showSymbol:false,
  14. symbolSize: 1,
  15. lineStyle: {
  16. width: 1,
  17. },
  18. emphasis: {
  19. scale:1.5
  20. }
  21. },
  22. show: false,
  23. option: {
  24. legend: {
  25. data: [
  26. ],
  27. selected: {
  28. },
  29. type: "scroll",
  30. width: '80%'
  31. },
  32. grid: {
  33. left: '0%', //默认10%
  34. right: '20px', //默认10%
  35. bottom: '20px', //默认60
  36. top: '60px',
  37. containLabel: true
  38. //grid区域是否包含坐标轴的刻度标签
  39. },
  40. xAxis: {
  41. data: []
  42. },
  43. yAxis: [
  44. {
  45. name: '排放量(tCO2e)',
  46. type: 'value',
  47. nameTextStyle: {
  48. padding: [0, 0, 0, 50]
  49. },
  50. },
  51. ],
  52. dataZoom: this.$constant.ECHARTS_OPTION_DATAZOOM,
  53. tooltip: {
  54. trigger: 'axis',
  55. axisPointer: {
  56. type: 'shadow'
  57. },
  58. textStyle: {
  59. color: '#fff',
  60. align: 'left',
  61. fontSize: 14
  62. },
  63. axisLine: {//x坐标轴轴线
  64. show: true,
  65. lineStyle: {//x坐标轴轴线样式
  66. color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  67. }
  68. },
  69. backgroundColor: 'rgba(0,0,0,0.8)',
  70. },
  71. series: []
  72. },
  73. }
  74. },
  75. props: {
  76. height: Number,
  77. queryData: Object,
  78. callBackCompanyOption: Function,
  79. },
  80. mounted() {
  81. this.$nextTick(()=>{
  82. this.init();
  83. })
  84. },
  85. methods: {
  86. init() {
  87. let chart = this.$echarts.init(this.$refs.myChart)
  88. this.chart = chart;
  89. this.$util.chartsResize(this.chart);
  90. chart.setOption(this.option)
  91. this.getData()
  92. },
  93. getData() {
  94. return apiCarbonPv.getPhotovoltaicInfo(this.queryData).then(res=>{
  95. let names = [];
  96. if (res.length>0) {
  97. let obj = res[0].jsonObject;
  98. for (const objKey in obj) {
  99. names.push(objKey);
  100. }
  101. }
  102. this.option.legend.data = names;
  103. let series = [];
  104. let selected = {};
  105. let comoptions = [];
  106. for (let i = 0; i < names.length; i++) {
  107. let obj = JSON.parse(JSON.stringify(this.seriesData));
  108. obj.name = names[i];
  109. series.push(obj);
  110. let opt = {
  111. label: names[i],
  112. value: i+1,
  113. }
  114. comoptions.push(opt)
  115. selected[names[i]+''] = false;
  116. }
  117. if (this.queryData.companyId != '0') {
  118. let name = names[Number(this.queryData.companyId)-1];
  119. selected[name] = true;
  120. } else {
  121. let name = names[0];
  122. selected[name] = true;
  123. }
  124. this.option.legend.selected = selected;
  125. this.callBackCompanyOption(comoptions)
  126. this.option.series = series;
  127. let data = this.$util.dataUtil.covertDataToEcharts(res, names)
  128. this.$util.dataUtil.refreshEchartsData(this.chart, this.option, data)
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <template>
  135. <div class="myChart" style="width: 100%" :style="{height: height+'px'}" ref="myChart" ></div>
  136. </template>
  137. <style lang="less" scoped>
  138. </style>