bottomLeftChart.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div>
  3. <div id="bottomLeftChart" style="width:11.25rem;height:6.25rem;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echartMixins from "@/utils/resizeMixins";
  8. export default {
  9. data() {
  10. return {
  11. chart: null
  12. };
  13. },
  14. mixins: [echartMixins],
  15. mounted() {
  16. this.draw();
  17. },
  18. methods: {
  19. draw() {
  20. // 基于准备好的dom,初始化echarts实例
  21. this.chart = this.echarts.init(document.getElementById("bottomLeftChart"));
  22. // ----------------------------------------------------------------
  23. let category = [
  24. "2021-01",
  25. "2021-01",
  26. "2021-01",
  27. "2021-01",
  28. "2021-01",
  29. "2021-01",
  30. "2021-01",
  31. "2021-01",
  32. "2021-01",
  33. "2021-01",
  34. "2021-01",
  35. "2021-01",
  36. "2021-01",
  37. "2021-01",
  38. "2021-01",
  39. "2021-01",
  40. "2021-01",
  41. "2021-01",
  42. "2021-01",
  43. "2021-01",
  44. "2021-01",
  45. "2021-01",
  46. "2021-01",
  47. "2021-01",
  48. "2021-01",
  49. "2021-01",
  50. "2021-01",
  51. "2021-01",
  52. "2021-01",
  53. "2021-01",
  54. "2021-01",
  55. "2021-01",
  56. "2021-01"
  57. ];
  58. let lineData = [
  59. 18092,
  60. 20728,
  61. 24045,
  62. 28348,
  63. 32808,
  64. 36097,
  65. 39867,
  66. 44715,
  67. 48444,
  68. 50415,
  69. 56061,
  70. 62677,
  71. 59521,
  72. 67560,
  73. 18092,
  74. 20728,
  75. 24045,
  76. 28348,
  77. 32808,
  78. 36097,
  79. 39867,
  80. 44715,
  81. 48444,
  82. 50415,
  83. 36097,
  84. 39867,
  85. 44715,
  86. 48444,
  87. 50415,
  88. 50061,
  89. 32677,
  90. 49521,
  91. 32808
  92. ];
  93. let barData = [
  94. 4600,
  95. 5000,
  96. 5500,
  97. 6500,
  98. 7500,
  99. 8500,
  100. 9900,
  101. 12500,
  102. 14000,
  103. 21500,
  104. 23200,
  105. 24450,
  106. 25250,
  107. 33300,
  108. 4600,
  109. 5000,
  110. 5500,
  111. 6500,
  112. 7500,
  113. 8500,
  114. 9900,
  115. 22500,
  116. 14000,
  117. 21500,
  118. 8500,
  119. 9900,
  120. 12500,
  121. 14000,
  122. 21500,
  123. 23200,
  124. 24450,
  125. 25250,
  126. 7500
  127. ];
  128. let rateData = [];
  129. for (let i = 0; i < 33; i++) {
  130. let rate = barData[i] / lineData[i];
  131. rateData[i] = rate.toFixed(2);
  132. }
  133. let option = {
  134. title: {
  135. text: "",
  136. x: "center",
  137. y: 0,
  138. textStyle: {
  139. color: "#B4B4B4",
  140. fontSize: 16,
  141. fontWeight: "normal"
  142. }
  143. },
  144. tooltip: {
  145. trigger: "axis",
  146. backgroundColor: "rgba(255,255,255,0.1)",
  147. axisPointer: {
  148. type: "shadow",
  149. label: {
  150. show: true,
  151. backgroundColor: "#7B7DDC"
  152. }
  153. }
  154. },
  155. legend: {
  156. data: [this.$t('已排放'),this.$t('计划排放'),this.$t('排放率')],
  157. textStyle: {
  158. color: "#B4B4B4"
  159. },
  160. top: "0%"
  161. },
  162. grid: {
  163. x: "8%",
  164. width: "88%",
  165. y: "4%"
  166. },
  167. xAxis: {
  168. data: category,
  169. axisLine: {
  170. lineStyle: {
  171. color: "#B4B4B4"
  172. }
  173. },
  174. axisTick: {
  175. show: false
  176. }
  177. },
  178. yAxis: [
  179. {
  180. splitLine: { show: false },
  181. axisLine: {
  182. lineStyle: {
  183. color: "#B4B4B4"
  184. }
  185. },
  186. axisLabel: {
  187. formatter: "{value} "
  188. }
  189. },
  190. {
  191. splitLine: { show: false },
  192. axisLine: {
  193. lineStyle: {
  194. color: "#B4B4B4"
  195. }
  196. },
  197. axisLabel: {
  198. formatter: "{value} "
  199. }
  200. }
  201. ],
  202. series: [
  203. {
  204. name: this.$t('排放率'),
  205. type: "line",
  206. smooth: true,
  207. showAllSymbol: true,
  208. symbol: "emptyCircle",
  209. symbolSize: 8,
  210. yAxisIndex: 1,
  211. itemStyle: {
  212. normal: {
  213. color: "#F02FC2"
  214. }
  215. },
  216. data: rateData
  217. },
  218. {
  219. name: this.$t('已排放'),
  220. type: "bar",
  221. barWidth: 10,
  222. itemStyle: {
  223. normal: {
  224. barBorderRadius: 5,
  225. color: new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
  226. { offset: 0, color: "#956FD4" },
  227. { offset: 1, color: "#3EACE5" }
  228. ])
  229. }
  230. },
  231. data: barData
  232. },
  233. {
  234. name: this.$t('计划排放'),
  235. type: "bar",
  236. barGap: "-100%",
  237. barWidth: 10,
  238. itemStyle: {
  239. normal: {
  240. barBorderRadius: 5,
  241. color: new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
  242. { offset: 0, color: "rgba(156,107,211,0.8)" },
  243. { offset: 0.2, color: "rgba(156,107,211,0.5)" },
  244. { offset: 1, color: "rgba(156,107,211,0.2)" }
  245. ])
  246. }
  247. },
  248. z: -12,
  249. data: lineData
  250. }
  251. ]
  252. };
  253. this.chart.setOption(option);
  254. }
  255. },
  256. destroyed() {
  257. window.onresize = null;
  258. }
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. </style>