wavyLineChart.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <!-- 面积图 -->
  2. <!-- 必须传入 ID area dataArray-->
  3. <template>
  4. <div>
  5. <boxTop :title="title" />
  6. <div class="wavylineBox" :style="{ width: barWidth }">
  7. <div class="chartsdom" :id="id"></div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import boxTop from '@/components/boxTop/index.vue'
  13. export default {
  14. data() {
  15. return {
  16. option: null,
  17. information: {},
  18. }
  19. },
  20. components: {
  21. boxTop,
  22. },
  23. props: {
  24. id: {
  25. type: String,
  26. default: ``,
  27. },
  28. smooth: {
  29. type: String,
  30. default: ``,
  31. },
  32. barWidth: {
  33. type: String,
  34. default: `401px`,
  35. },
  36. area: {
  37. type: Array,
  38. },
  39. dataArray: {
  40. type: Object,
  41. },
  42. lineName: {
  43. type: Object,
  44. },
  45. title: {
  46. type: String,
  47. default: ``,
  48. },
  49. unit: {
  50. type: String,
  51. default: ``,
  52. },
  53. },
  54. mounted() {
  55. this.getEchart()
  56. },
  57. watch: {
  58. dataArray() {
  59. this.getEchart()
  60. },
  61. },
  62. methods: {
  63. getEchart() {
  64. let myChart = echarts.init(document.getElementById(this.id))
  65. this.option = {
  66. backgroundColor: `rgb(0,0,0,0.3)`,
  67. color: [
  68. `#23CF9C`,
  69. `#578FFB`,
  70. `#6E40F2`,
  71. `#FF61E6`,
  72. `#8B5CFF`,
  73. `#00CA69`,
  74. ],
  75. legend: {
  76. selectedMode: false,
  77. icon: `circle`,
  78. top: `5%`,
  79. right: `5%`,
  80. itemWidth: 6,
  81. itemGap: 20,
  82. textStyle: {
  83. color: `#94A7BD`,
  84. },
  85. },
  86. tooltip: {
  87. trigger: `axis`,
  88. backgroundColor: `rgba(9,40,84,0.8)`,
  89. borderColor: `rgba(9,40,84,0.8)`,
  90. textStyle: {
  91. fontSize: 17,
  92. color: `#fff`,
  93. },
  94. axisPointer: {
  95. type: `shadow`,
  96. },
  97. formatter: function (params) {
  98. console.log(params)
  99. const temMarkerStyle =
  100. `display: inline-block; width: 14px; height: 14px;border-radius:14px; margin-right:3px; background-color: ` +
  101. params[0].color +
  102. `;`
  103. const humMarkerStyle =
  104. `display: inline-block; width: 14px; height: 14px; margin-right:3px;border-radius:14px; background-color: ` +
  105. params[1].color +
  106. `;`
  107. if (params.length > 2) {
  108. let name = `较上日`
  109. if (params[0].axisValue.length < 8) {
  110. name = `较上月`
  111. }
  112. let name1 = `较上月`
  113. if (params[0].axisValue.length < 8) {
  114. name1 = `较去年`
  115. }
  116. return [
  117. `${`<span style="` + temMarkerStyle + `"></span>`}` +
  118. params[0].axisValue +
  119. `<i style="padding:0 6px"></i> ` +
  120. params[0].value +
  121. `<i style="padding:0 12px"></i> ` +
  122. `${name}` +
  123. `<span style="padding:0 6px;color:${
  124. params[2].value > 0 ? `#1DEFB3` : `#FF8D00`
  125. }">${params[2].value}%</span> `,
  126. `${`<span style="` + humMarkerStyle + `"></span>`}` +
  127. params[1].axisValue +
  128. `<i style="padding:0 6px"></i> ` +
  129. params[1].value +
  130. `<i style="padding:0 12px"></i> ` +
  131. `${name1}` +
  132. `<span style="padding:0 6px;color:${
  133. params[3].value > 0 ? `#1DEFB3` : `#FF8D00`
  134. }">${params[3].value}%</span> `,
  135. ].join(`<br>`)
  136. } else {
  137. return [
  138. params[0].axisValue,
  139. `${`<span style="` + temMarkerStyle + `"></span>`}` +
  140. `今年` +
  141. `<i style="padding:0 6px"></i> ` +
  142. params[0].value,
  143. `${`<span style="` + humMarkerStyle + `"></span>`}` +
  144. `去年` +
  145. `<i style="padding:0 6px"></i> ` +
  146. params[1].value,
  147. ].join(`<br>`)
  148. }
  149. },
  150. },
  151. grid: {
  152. top: `20%`,
  153. left: `4%`,
  154. right: `4%`,
  155. bottom: `10%`,
  156. containLabel: true,
  157. },
  158. xAxis: {
  159. type: `category`,
  160. boundaryGap: true,
  161. axisLabel: {
  162. // formatter: `{value}`,
  163. textStyle: {
  164. color: `#c7d6f2`,
  165. },
  166. },
  167. axisLine: {
  168. lineStyle: {
  169. color: `#D9D9D9`,
  170. },
  171. },
  172. data: this.area,
  173. },
  174. yAxis: {
  175. type: `value`,
  176. name: this.unit,
  177. axisLabel: {
  178. textStyle: {
  179. color: `#65ABE7`,
  180. },
  181. },
  182. nameTextStyle: {
  183. color: `#65ABE7`,
  184. fontSize: 12,
  185. lineHeight: 40,
  186. },
  187. splitLine: {
  188. lineStyle: {
  189. type: `dashed`,
  190. color: `#182D46`,
  191. },
  192. },
  193. axisLine: {
  194. show: false,
  195. },
  196. axisTick: {
  197. show: false,
  198. },
  199. },
  200. series: [
  201. {
  202. name: this.lineName.thisName,
  203. type: `line`,
  204. smooth: this.smooth == `true` ? true : false,
  205. symbol: `none`,
  206. symbolSize: 8,
  207. zlevel: 3,
  208. areaStyle: {
  209. normal: {
  210. color: new echarts.graphic.LinearGradient(
  211. 0,
  212. 0,
  213. 0,
  214. 1,
  215. [
  216. {
  217. offset: 0,
  218. color: `#23CF9C30`,
  219. },
  220. {
  221. offset: 1,
  222. color: `#23CF9C10`,
  223. },
  224. ],
  225. false
  226. ),
  227. shadowColor: `#23CF9C10`,
  228. shadowBlur: 10,
  229. },
  230. },
  231. data: this.dataArray.thisYear,
  232. },
  233. {
  234. name: this.lineName.lastName,
  235. type: `line`,
  236. smooth: this.smooth,
  237. symbol: `none`,
  238. symbolSize: 8,
  239. zlevel: 3,
  240. areaStyle: {
  241. normal: {
  242. color: new echarts.graphic.LinearGradient(
  243. 0,
  244. 0,
  245. 0,
  246. 1,
  247. [
  248. {
  249. offset: 0,
  250. color: `#578FFB30`,
  251. },
  252. {
  253. offset: 1,
  254. color: `#578FFB10`,
  255. },
  256. ],
  257. false
  258. ),
  259. shadowColor: `#578FFB10`,
  260. shadowBlur: 10,
  261. },
  262. },
  263. data: this.dataArray.LastYear,
  264. },
  265. {
  266. data: this.dataArray.comparisonLastDay,
  267. type: `line`,
  268. symbolSize: 0, // symbol的大小设置为0
  269. showSymbol: false, // 不显示symbol
  270. lineStyle: {
  271. width: 0, // 线宽是0
  272. color: `rgba(0, 0, 0, 0)`, // 线的颜色是透明的
  273. },
  274. },
  275. {
  276. data: this.dataArray.comparisonLastYear,
  277. type: `line`,
  278. symbolSize: 0, // symbol的大小设置为0
  279. showSymbol: false, // 不显示symbol
  280. lineStyle: {
  281. width: 0, // 线宽是0
  282. color: `rgba(0, 0, 0, 0)`, // 线的颜色是透明的
  283. },
  284. },
  285. ],
  286. }
  287. myChart.setOption(this.option, true)
  288. },
  289. },
  290. beforeDestroy() {},
  291. }
  292. </script>
  293. <style lang="less" scoped>
  294. .wavylineBox {
  295. width: 448px;
  296. height: 266px;
  297. .chartsdom {
  298. width: 100%;
  299. height: 100%;
  300. }
  301. }
  302. </style>