carbonEmissionChart.vue 3.4 KB

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