carbonCarEmissionChart.vue 3.5 KB

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