index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <div class="wrap">
  3. <div class="chart-wrap">
  4. <v-chart autoresize :option="option"/>
  5. </div>
  6. <div class="tip">
  7. <img src="/static/images/syjhTIP.png">
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import {chartDlydts, chartSyjhdxqk} from '@/api/dashboard-json'
  13. export default {
  14. name: 'SyjhdxqkChart',
  15. data() {
  16. return {
  17. option: {},
  18. arrMap: {
  19. '开关分合计划': [],
  20. '单体计划': []
  21. }
  22. }
  23. },
  24. created() {
  25. this.getOption()
  26. },
  27. methods: {
  28. async getOption() {
  29. const res = await chartSyjhdxqk()
  30. if (res?.code === 200) {
  31. const arrMap = {
  32. '开关分合计划': [],
  33. '单体计划': []
  34. }
  35. // const max =
  36. res.info.xaxis.forEach((item, index) => {
  37. const valItem = {
  38. name: item,
  39. value: res.info.series[1].data[index],
  40. used: res.info.series[1].data[index],
  41. total: res.info.series[0].data[index],
  42. totalLabel: res.info.series[0].data[index]
  43. }
  44. arrMap['开关分合计划'].push(valItem)
  45. const valItem2 = {
  46. name: item,
  47. value: res.info.series[3].data[index],
  48. used: res.info.series[3].data[index],
  49. total: res.info.series[2].data[index],
  50. totalLabel: res.info.series[2].data[index]
  51. }
  52. arrMap['单体计划'].push(valItem2)
  53. })
  54. arrMap['开关分合计划'].forEach(item => {
  55. if (item.used > item.total) {
  56. item.total = item.used
  57. }
  58. })
  59. arrMap['单体计划'].forEach(item => {
  60. if (item.used > item.total) {
  61. item.total = item.used
  62. }
  63. })
  64. this.arrMap = arrMap
  65. }
  66. const baseWidth = this.EchartfontSize(14)
  67. const offsetWidth = this.EchartfontSize(14)
  68. const triangleHeight = 8
  69. this.option = {
  70. color: [],
  71. grid: {
  72. containLabel: true,
  73. left: 20,
  74. right: 20,
  75. bottom: 10,
  76. top: 70
  77. },
  78. xAxis: {
  79. data: ['第一季度', '第二季度', '第三季度', '第四季度'],
  80. type: 'category',
  81. axisLabel: {
  82. color: 'rgba(255,255,255,0.8)',
  83. fontSize: this.EchartfontSize(12),
  84. formatter: (name) => {
  85. return `\n` + name
  86. }
  87. },
  88. position: 'bottom',
  89. label: {}
  90. // offset: [0]
  91. },
  92. yAxis: {
  93. axisLabel: {
  94. color: '#ffffff',
  95. fontSize: this.EchartfontSize(14)
  96. },
  97. axisTick: {
  98. lineStyle: {
  99. color: '#384267',
  100. width: 0
  101. },
  102. show: true
  103. },
  104. splitLine: {
  105. show: false,
  106. lineStyle: {
  107. color: '#384267',
  108. type: 'dashed'
  109. }
  110. },
  111. axisLine: {
  112. lineStyle: {
  113. color: '#ffffff',
  114. width: 0,
  115. type: 'dashed'
  116. },
  117. show: true
  118. },
  119. name: ''
  120. },
  121. series: [
  122. {
  123. // data: [200, 85, 112, 275],
  124. data: this.arrMap['开关分合计划'].map(item => item.used),
  125. type: 'pictorialBar',
  126. symbol: 'rect',
  127. symbolSize: ['100%', '100%'],
  128. symbolOffset: [-offsetWidth, 0],
  129. barMaxWidth: 'auto',
  130. barWidth: baseWidth,
  131. itemStyle: {
  132. color: {
  133. x: 0,
  134. y: 0,
  135. x2: 0,
  136. y2: 1,
  137. type: 'linear',
  138. global: false,
  139. colorStops: [
  140. {
  141. offset: 0,
  142. color: 'rgb(106, 169, 216)'
  143. },
  144. {
  145. offset: 1,
  146. color: 'rgb(54, 125, 181)'
  147. }
  148. ]
  149. }
  150. },
  151. zlevel: 1
  152. },
  153. {
  154. data: [1, 1, 1, 1],
  155. type: 'pictorialBar',
  156. symbol: 'triangle',
  157. symbolRotate: 180,
  158. symbolOffset: [-offsetWidth, '96%'],
  159. symbolSize: ['100%', triangleHeight],
  160. barMaxWidth: 'auto',
  161. barWidth: baseWidth,
  162. itemStyle: {
  163. color: 'rgb(54, 125, 181)'
  164. },
  165. zlevel: 1
  166. },
  167. {
  168. // data: [200, 85, 112, 275],
  169. data: this.arrMap['开关分合计划'].map(item => item.used),
  170. type: 'pictorialBar',
  171. symbolPosition: 'end',
  172. symbol: 'triangle',
  173. symbolRotate: 180,
  174. symbolSize: [baseWidth, triangleHeight],
  175. symbolOffset: [-offsetWidth, '-0%'],
  176. barMaxWidth: 'auto',
  177. barWidth: baseWidth,
  178. itemStyle: {
  179. color: 'rgb(159, 214, 253)'
  180. },
  181. zlevel: 2
  182. },
  183. {
  184. // data: [600, 541, 741, 741],
  185. data: this.arrMap['开关分合计划'].map(item => item.total),
  186. type: 'pictorialBar',
  187. symbol: 'rect',
  188. symbolSize: [baseWidth, '100%'],
  189. symbolOffset: [-offsetWidth, 0],
  190. barMaxWidth: 'auto',
  191. barWidth: baseWidth,
  192. itemStyle: {
  193. color: {
  194. x: 0,
  195. y: 0,
  196. x2: 0,
  197. y2: 1,
  198. type: 'linear',
  199. global: false,
  200. colorStops: [
  201. {
  202. offset: 0,
  203. color: 'rgb(35, 55, 81)'
  204. },
  205. {
  206. offset: 1,
  207. color: 'rgb(30, 52, 75)'
  208. }
  209. ]
  210. }
  211. },
  212. label: {
  213. show: true,
  214. distance: 10,
  215. color: 'rgba(255,255,255,0.76)',
  216. fontSize: this.EchartfontSize(10),
  217. position: [-baseWidth - offsetWidth / this.EchartfontSize(10), -this.EchartfontSize(30)],
  218. formatter: (evt) => {
  219. const item = this.arrMap['开关分合计划']?.[evt.dataIndex] || {}
  220. return `${item.value}\n /\n${item.totalLabel}`
  221. }
  222. },
  223. zlevel: -1
  224. },
  225. {
  226. // data: [600, 541, 741, 741],
  227. data: this.arrMap['开关分合计划'].map(item => item.total),
  228. type: 'pictorialBar',
  229. symbolPosition: 'end',
  230. symbol: 'triangle',
  231. symbolRotate: 180,
  232. symbolSize: [baseWidth, triangleHeight],
  233. symbolOffset: [-offsetWidth, '0%'],
  234. barMaxWidth: 'auto',
  235. barWidth: baseWidth,
  236. itemStyle: {
  237. color: 'rgb(49, 70, 97)'
  238. },
  239. zlevel: 1
  240. },
  241. // 2
  242. {
  243. // data: [160, 410, 112, 275],
  244. data: this.arrMap['单体计划'].map(item => item.used),
  245. type: 'pictorialBar',
  246. symbol: 'rect',
  247. symbolSize: [baseWidth, '100%'],
  248. symbolOffset: [offsetWidth, '0%'],
  249. barMaxWidth: 'auto',
  250. barWidth: baseWidth,
  251. itemStyle: {
  252. color: {
  253. x: 0,
  254. y: 0,
  255. x2: 0,
  256. y2: 1,
  257. type: 'linear',
  258. global: false,
  259. colorStops: [
  260. {
  261. offset: 0,
  262. color: 'rgb(107, 204, 220)'
  263. },
  264. {
  265. offset: 1,
  266. color: 'rgb(57, 154, 178)'
  267. }
  268. ]
  269. }
  270. },
  271. zlevel: 1
  272. },
  273. {
  274. data: [1, 1, 1, 1],
  275. type: 'pictorialBar',
  276. symbol: 'triangle',
  277. symbolRotate: 180,
  278. symbolSize: [baseWidth, triangleHeight],
  279. symbolOffset: [offsetWidth, '96%'],
  280. barMaxWidth: 'auto',
  281. barWidth: baseWidth,
  282. itemStyle: {
  283. color: 'rgb(57, 154, 178)'
  284. },
  285. zlevel: 1
  286. },
  287. {
  288. // data: [160, 410, 112, 275],
  289. data: this.arrMap['单体计划'].map(item => item.used),
  290. type: 'pictorialBar',
  291. symbolPosition: 'end',
  292. symbol: 'triangle',
  293. symbolRotate: 180,
  294. symbolSize: [baseWidth, triangleHeight],
  295. symbolOffset: [offsetWidth, '0%'],
  296. barMaxWidth: 'auto',
  297. barWidth: baseWidth,
  298. itemStyle: {
  299. color: 'rgb(159, 214, 253)'
  300. },
  301. zlevel: 2
  302. },
  303. {
  304. // data: [580, 541, 741, 420],
  305. data: this.arrMap['单体计划'].map(item => item.total),
  306. type: 'pictorialBar',
  307. symbol: 'rect',
  308. symbolSize: [baseWidth, '100%'],
  309. symbolOffset: [offsetWidth, '0%'],
  310. barMaxWidth: 'auto',
  311. barWidth: baseWidth,
  312. itemStyle: {
  313. color: {
  314. x: 0,
  315. y: 0,
  316. x2: 0,
  317. y2: 1,
  318. type: 'linear',
  319. global: false,
  320. colorStops: [
  321. {
  322. offset: 0,
  323. color: 'rgb(33, 59, 72)'
  324. },
  325. {
  326. offset: 1,
  327. color: 'rgb(30, 64, 78)'
  328. }
  329. ]
  330. }
  331. },
  332. label: {
  333. show: true,
  334. distance: 10,
  335. color: 'rgba(255,255,255,0.76)',
  336. fontSize: this.EchartfontSize(10),
  337. position: [baseWidth + 4 - offsetWidth / this.EchartfontSize(2), -this.EchartfontSize(30)],
  338. formatter: (evt) => {
  339. const item = this.arrMap['单体计划']?.[evt.dataIndex] || {}
  340. return `${item.value}\n /\n${item.totalLabel}`
  341. }
  342. },
  343. zlevel: -1
  344. },
  345. {
  346. // data: [580, 541, 741, 420],
  347. data: this.arrMap['单体计划'].map(item => item.total),
  348. type: 'pictorialBar',
  349. symbolPosition: 'end',
  350. symbol: 'triangle',
  351. symbolRotate: 180,
  352. symbolSize: [baseWidth, triangleHeight],
  353. symbolOffset: [offsetWidth, '0%'],
  354. barMaxWidth: 'auto',
  355. barWidth: baseWidth,
  356. itemStyle: {
  357. color: 'rgb(49, 70, 97)'
  358. },
  359. zlevel: 1
  360. }
  361. ],
  362. tooltip: {
  363. trigger: 'axis',
  364. show: false
  365. }
  366. }
  367. }
  368. }
  369. }
  370. </script>
  371. <style scoped lang="scss">
  372. $xHeight: 120px;
  373. .wrap {
  374. width: 100%;
  375. height: 100%;
  376. position: relative;
  377. .tip {
  378. position: absolute;
  379. z-index: 1;
  380. right: 1.5vw;
  381. top: 0;
  382. img {
  383. height: 20px;
  384. width: auto;
  385. object-fit: cover;
  386. opacity: 0.7;
  387. }
  388. }
  389. }
  390. .chart-wrap {
  391. width: 100%;
  392. height: 100%;
  393. .left-bar {
  394. width: 35px;
  395. display: inline-block;
  396. }
  397. .right-conent {
  398. width: calc(100% - 35px);
  399. height: 100%;
  400. display: grid;
  401. grid-template-columns: 1fr 1fr 1fr 1fr;
  402. grid-template-rows: auto $xHeight;
  403. }
  404. }
  405. </style>