index.vue 11 KB

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