index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class="chart-wrap">
  3. <div class="wrap-fix">
  4. <div class="col-1 col">
  5. <v-chart autoresize :option="option1"/>
  6. </div>
  7. <div class="col-2 col">
  8. <v-chart autoresize :option="option2"/>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import * as echarts from 'echarts'
  15. import {chartMapTable} from '@/api/dashboard-json'
  16. export default {
  17. name: 'Jryl',
  18. data() {
  19. return {
  20. option1: {},
  21. option2: {}
  22. }
  23. },
  24. created() {
  25. this.getOption()
  26. },
  27. methods: {
  28. async getOption() {
  29. let arrMap = []
  30. const res = await chartMapTable()
  31. if (res.code === 200) {
  32. arrMap = [
  33. [res.info.series[0].data[0], res.info.series[1].data[0]],
  34. [res.info.series[0].data[1], res.info.series[1].data[1]],
  35. [res.info.series[0].data[2], res.info.series[1].data[2]]
  36. ]
  37. }
  38. var xData2 = ['变电']
  39. var data = arrMap || [
  40. [50, 10],
  41. [100, 10],
  42. [80, 10]
  43. ]
  44. const data1 = [
  45. [data[0][0]],
  46. [data[1][0]],
  47. [data[2][0]]
  48. ]
  49. const data2 = [
  50. [data[0][1]],
  51. [data[1][1]],
  52. [data[2][1]]
  53. ]
  54. const xDataSum = [arrMap[0][0] + arrMap[1][0] + arrMap[2][0], arrMap[0][1] + arrMap[1][1] + arrMap[2][1]]
  55. window['xDataSum'] = xDataSum
  56. const gapWidth = this.EchartfontSize(125)
  57. const barWidth = this.EchartfontSize(10)
  58. const symbolOffsetWidth = this.EchartfontSize(1)
  59. const symbolSizeWidth = this.EchartfontSize(4)
  60. const barGap = 10
  61. const params = {
  62. xData2: xData2,
  63. data: data2,
  64. gapWidth,
  65. barWidth,
  66. symbolOffsetWidth,
  67. symbolSizeWidth,
  68. barGap,
  69. xDataSum
  70. }
  71. this.renderOption('option1', params)
  72. const params2 = {
  73. xData2: ['电力'],
  74. data: data1,
  75. gapWidth,
  76. barWidth,
  77. symbolOffsetWidth,
  78. symbolSizeWidth,
  79. barGap,
  80. xDataSum
  81. }
  82. this.renderOption('option2', params2)
  83. },
  84. renderOption(optionName, params) {
  85. const {
  86. xData2,
  87. data,
  88. gapWidth,
  89. barWidth,
  90. symbolOffsetWidth,
  91. symbolSizeWidth,
  92. barGap,
  93. xDataSum
  94. } = params
  95. window['params'] = params
  96. window['tis'] = this
  97. let sealingData = []
  98. const gapPerSize = 3
  99. const gapData = data.map((item) => {
  100. if (item[0] === 0) {
  101. return [0, 0, 0]
  102. } else {
  103. return [gapPerSize, gapPerSize, gapPerSize]
  104. }
  105. })
  106. data.forEach((item, index) => {
  107. let sealingBeforeItem = item
  108. let sealingStart = [0, 0, 0]
  109. let sealingEnd = sealingBeforeItem
  110. if (index > 0) {
  111. sealingBeforeItem = sealingData[index - 1][1]
  112. sealingStart = sealingBeforeItem.map((d) => {
  113. if (d > 0) {
  114. return d + gapPerSize
  115. } else {
  116. return d
  117. }
  118. })
  119. sealingEnd = sealingBeforeItem.map((d, dIndex) => {
  120. if (d > 0) {
  121. return d + gapPerSize + item[dIndex]
  122. } else {
  123. return d + item[dIndex]
  124. }
  125. })
  126. }
  127. sealingData[index] = [sealingStart, sealingEnd]
  128. })
  129. // 三条数据变两条
  130. sealingData = JSON.parse(JSON.stringify(sealingData))
  131. sealingData.forEach((item, index) => {
  132. const start = item[0].splice(0, data[0].length)
  133. const end = item[1].splice(0, data[0].length)
  134. sealingData[index] = [start, end]
  135. })
  136. this[optionName] = {
  137. tooltip: {
  138. show: false,
  139. trigger: 'item'
  140. },
  141. legend: {
  142. selectedMode: false,
  143. show: optionName !== 'option2',
  144. top: '5%',
  145. right: '30%',
  146. width: '100%',
  147. height: '0%',
  148. // orient: 'vertical',
  149. textStyle: {
  150. color: '#ffffff',
  151. fontSize: this.EchartfontSize(12)
  152. },
  153. data: [
  154. {
  155. name: '一级',
  156. // 强制设置图形为圆。
  157. icon: `image://${window.location.origin}/static/images/icon_red@2x.png`,
  158. // 设置文本为红色
  159. textStyle: {
  160. color: '#ffffff'
  161. }
  162. },
  163. {
  164. name: '二级',
  165. // 强制设置图形为圆。
  166. icon: `image://${window.location.origin}/static/images/icon_yellow@2x.png`,
  167. // 设置文本为红色
  168. textStyle: {
  169. color: '#ffffff'
  170. }
  171. },
  172. {
  173. name: '三级',
  174. // 强制设置图形为圆。
  175. icon: `image://${window.location.origin}/static/images/icon_blue@2x.png`,
  176. // 设置文本为红色
  177. textStyle: {
  178. color: '#ffffff'
  179. }
  180. }
  181. ]
  182. },
  183. grid: {
  184. right: '10%',
  185. left: '5%',
  186. height: '80%',
  187. top: optionName === 'option2' ? '10%' : '50%',
  188. bottom: optionName === 'option2' ? '0%' : 0,
  189. containLabel: true
  190. },
  191. xAxis: {
  192. show: false,
  193. type: 'value',
  194. splitLine: {
  195. show: false
  196. },
  197. axisTick: {
  198. show: false
  199. },
  200. axisLine: {
  201. show: false
  202. },
  203. axisLabel: {
  204. show: true,
  205. fontSize: this.EchartfontSize(16),
  206. color: '#ffffff',
  207. formatter: (name) => {
  208. return name + ' '
  209. }
  210. }
  211. },
  212. yAxis: {
  213. data: xData2,
  214. type: 'category',
  215. splitLine: {
  216. show: false
  217. },
  218. axisTick: {
  219. show: false
  220. },
  221. axisLine: {
  222. show: false
  223. },
  224. axisLabel: {
  225. fontSize: this.EchartfontSize(12),
  226. color: 'rgba(255,255,255,0.8)',
  227. formatter: (name) => {
  228. return name + ' '
  229. }
  230. }
  231. },
  232. series: [
  233. { // 一级
  234. name: '一级',
  235. type: 'bar',
  236. stack: 'total',
  237. barGap: barGap, /* 多个并排柱子设置柱子之间的间距*/
  238. barCategoryGap: 10, /* 多个并排柱子设置柱子之间的间距*/
  239. barWidth: barWidth,
  240. itemStyle: { // lenged文本
  241. opacity: 1,
  242. color: () => {
  243. return new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
  244. offset: 0,
  245. color: 'rgba(231, 73, 2, 0.30)' // 0% 处的颜色
  246. }, {
  247. offset: 1,
  248. color: 'rgba(231, 73, 2, 0.60)' // 100% 处的颜色
  249. }], false)
  250. }
  251. },
  252. label: {
  253. show: true,
  254. position: ['50%', -barWidth - 10],
  255. fontSize: this.EchartfontSize(16),
  256. color: '#ffffff',
  257. formatter: (evt) => {
  258. return data[0][0] > 0 ? (evt || {})?.value : ' '
  259. }
  260. },
  261. data: data[0]
  262. },
  263. { // gap
  264. name: '',
  265. type: 'bar',
  266. barWidth: gapWidth,
  267. stack: 'total',
  268. z: 0,
  269. itemStyle: {
  270. color: 'rgba(255,0,0,1)',
  271. opacity: 0
  272. },
  273. data: data[0][0] === 0 ? [0] : gapData[0]
  274. },
  275. { // 二级
  276. name: '二级',
  277. type: 'bar',
  278. stack: 'total',
  279. barWidth: barWidth,
  280. itemStyle: { // lenged文本
  281. opacity: 1,
  282. color: (params) => {
  283. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  284. offset: 0,
  285. color: 'rgba(231, 203, 2, 0.30)' // 0% 处的颜色
  286. }, {
  287. offset: 1,
  288. color: 'rgb(72, 72, 36)' // 100% 处的颜色
  289. }], false)
  290. }
  291. },
  292. label: {
  293. show: true,
  294. position: ['50%', -barWidth - 10],
  295. fontSize: this.EchartfontSize(16),
  296. color: '#fffff',
  297. formatter: (evt) => {
  298. return data[1][0] > 0 ? evt.value : ' '
  299. }
  300. },
  301. data: data[1]
  302. },
  303. { // gap
  304. name: '',
  305. type: 'bar',
  306. barWidth: gapWidth,
  307. stack: 'total',
  308. z: 0,
  309. itemStyle: {
  310. color: 'rgba(255,0,0,1)',
  311. opacity: 0
  312. },
  313. data: data[1][0] === 0 ? [0] : gapData[1]
  314. },
  315. { // 三级
  316. name: '三级',
  317. type: 'bar',
  318. stack: 'total',
  319. barWidth: barWidth,
  320. itemStyle: { // lenged文本
  321. opacity: 1,
  322. color: (params) => {
  323. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  324. offset: 0,
  325. color: 'rgba(78, 231, 255, 0.30)' // 0% 处的颜色
  326. }, {
  327. offset: 1,
  328. color: 'rgba(78, 231, 255, 0.60)' // 100% 处的颜色
  329. }], false)
  330. }
  331. },
  332. label: {
  333. show: true,
  334. position: ['50%', -barWidth - 10],
  335. fontSize: this.EchartfontSize(16),
  336. color: '#fffff',
  337. formatter: (evt) => {
  338. return data[2][0] > 0 ? evt.value : ' '
  339. }
  340. },
  341. data: data[2]
  342. },
  343. // { // 替代柱状图 默认不显示颜色,是最下方柱图(邮件营销)的value值 - 20
  344. // type: 'bar',
  345. // barWidth: barWidth,
  346. // barGap: '-100%',
  347. // stack: '广告',
  348. // itemStyle: {
  349. // color: 'transparent'
  350. // },
  351. // data: data1
  352. // },
  353. { // 封口1
  354. 'name': '',
  355. 'type': 'pictorialBar',
  356. 'symbol': 'circle',
  357. 'symbolRotate': 180,
  358. 'symbolSize': [symbolSizeWidth, barWidth],
  359. 'symbolOffset': [symbolOffsetWidth, 0],
  360. itemStyle: {
  361. opacity: data[0][0] === 0 ? 0 : 1,
  362. color: (params) => {
  363. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  364. offset: 0,
  365. color: 'rgba(237, 118, 101,.4)' // 0% 处的颜色
  366. }, {
  367. offset: 1,
  368. color: 'rgba(237, 118, 101, .0)' // 100% 处的颜色
  369. }], false)
  370. }
  371. },
  372. label: {},
  373. 'symbolPosition': 'start',
  374. 'data': [sealingData[0][0][0], sealingData[0][0][0]]
  375. },
  376. { // 封口2
  377. 'name': '',
  378. 'type': 'pictorialBar',
  379. 'symbolSize': [symbolSizeWidth, barWidth],
  380. 'symbolRotate': 180,
  381. 'symbolOffset': [symbolOffsetWidth, 0],
  382. 'symbolPosition': 'end',
  383. 'z': 12,
  384. itemStyle: {
  385. opacity: data[0][0] === 0 ? 0 : 1,
  386. color: (params) => {
  387. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  388. offset: 0,
  389. color: 'rgba(237, 118, 101,1)' // 0% 处的颜色
  390. }, {
  391. offset: 1,
  392. color: 'rgba(237, 118, 101, 1)' // 100% 处的颜色
  393. }], false)
  394. }
  395. },
  396. 'data': sealingData[0][1]
  397. },
  398. { // 封口3
  399. 'name': '',
  400. 'type': 'pictorialBar',
  401. 'symbol': 'circle',
  402. 'symbolRotate': 180,
  403. 'symbolSize': [symbolSizeWidth, barWidth],
  404. 'symbolOffset': [symbolOffsetWidth, 0],
  405. 'z': 12,
  406. itemStyle: {
  407. opacity: data[1][0] === 0 ? 0 : 1,
  408. color: (params) => {
  409. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  410. offset: 0,
  411. color: 'rgba(255, 238, 91,.1)' // 0% 处的颜色
  412. }, {
  413. offset: 1,
  414. color: 'rgba(255, 238, 91, .6)' // 100% 处的颜色
  415. }], false)
  416. }
  417. },
  418. label: {
  419. // show: true,
  420. // position: 'top',
  421. // fontSize: 16,
  422. // color: '#fff'
  423. // formatter:(item)=>{
  424. // console.log(item)
  425. // return 'ssss'
  426. // }
  427. },
  428. 'symbolPosition': 'end',
  429. 'data': sealingData[1][0]
  430. },
  431. { // 封口4
  432. 'name': '',
  433. 'type': 'pictorialBar',
  434. 'symbolSize': [symbolSizeWidth, barWidth],
  435. 'symbolRotate': 180,
  436. 'symbolOffset': [symbolOffsetWidth, 0],
  437. 'symbolPosition': 'end',
  438. 'z': 12,
  439. itemStyle: {
  440. opacity: data[1][0] === 0 ? 0 : 1,
  441. color: (params) => {
  442. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  443. offset: 1,
  444. color: 'rgba(255, 238, 91, 1)' // 0% 处的颜色
  445. }, {
  446. offset: 1,
  447. color: 'rgba(255, 238, 91, 1)' // 100% 处的颜色
  448. }], false)
  449. }
  450. },
  451. 'data': sealingData[1][1]
  452. },
  453. { // 封口5
  454. 'name': '',
  455. 'type': 'pictorialBar',
  456. 'symbol': 'circle',
  457. 'symbolRotate': 180,
  458. 'symbolSize': [symbolSizeWidth, barWidth],
  459. 'symbolOffset': [symbolOffsetWidth, 0],
  460. 'z': 12,
  461. itemStyle: {
  462. opacity: data[2][0] === 0 ? 0 : 1,
  463. color: (params) => {
  464. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  465. offset: data[2][0] === 0 ? 0 : 1,
  466. color: 'rgba(162, 237, 255,.1)' // 0% 处的颜色
  467. }, {
  468. offset: 1,
  469. color: 'rgba(162, 237, 255,.6)' // 100% 处的颜色
  470. }], false)
  471. }
  472. },
  473. label: {
  474. // show: true,
  475. // position: 'top',
  476. // fontSize: 16,
  477. // color: '#fff'
  478. // formatter:(item)=>{
  479. // console.log(item)
  480. // return 'ssss'
  481. // }
  482. },
  483. 'symbolPosition': 'end',
  484. 'data': sealingData[2][0]
  485. },
  486. { // 封口6
  487. 'name': '',
  488. 'type': 'pictorialBar',
  489. 'symbolSize': [symbolSizeWidth, barWidth],
  490. 'symbolRotate': 180,
  491. 'symbolOffset': [symbolOffsetWidth, 0],
  492. 'symbolPosition': 'end',
  493. 'z': 12,
  494. show: false,
  495. itemStyle: {
  496. opacity: data[2][0] === 0 ? 0 : 1,
  497. color: (params) => {
  498. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  499. offset: 0,
  500. color: 'rgba(162, 237, 255,1)' // 0% 处的颜色
  501. }, {
  502. offset: 1,
  503. color: 'rgba(162, 237, 255,1)' // 100% 处的颜色
  504. }], false)
  505. }
  506. },
  507. 'data': sealingData[2][1]
  508. },
  509. { // right-value
  510. 'name': '',
  511. 'type': 'pictorialBar',
  512. 'symbolSize': [symbolSizeWidth, barWidth],
  513. 'symbolRotate': 180,
  514. 'symbolOffset': [symbolOffsetWidth, 0],
  515. 'symbolPosition': 'end',
  516. 'z': 12,
  517. itemStyle: {
  518. opacity: 1,
  519. color: (params) => {
  520. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  521. offset: 0,
  522. color: 'rgba(162, 237, 255,0)' // 0% 处的颜色
  523. }, {
  524. offset: 1,
  525. color: 'rgba(162, 237, 255,0)' // 100% 处的颜色
  526. }], false)
  527. }
  528. },
  529. 'data': sealingData[2][1].map(value => value + 10),
  530. label: {
  531. show: true,
  532. distance: 10,
  533. color: '#fff',
  534. fontSize: this.EchartfontSize(14),
  535. // position: [-baseWidth - offsetWidth / this.EchartfontSize(10), -this.EchartfontSize(20)]
  536. position: 'right',
  537. formatter: (item) => {
  538. if (optionName === 'option1') {
  539. return xDataSum[1]
  540. } else {
  541. return xDataSum[0]
  542. }
  543. }
  544. }
  545. }
  546. ]
  547. }
  548. }
  549. }
  550. }
  551. </script>
  552. <style scoped lang="scss">
  553. .chart-wrap {
  554. width: 100%;
  555. height: 100%;
  556. overflow: hidden;
  557. background: rgb(40, 42, 54, 0);
  558. .wrap-fix {
  559. height: 100%;
  560. width: 100%;
  561. display: flex;
  562. flex-direction: column;
  563. .col {
  564. flex: 1;
  565. flex-shrink: 0;
  566. }
  567. }
  568. }
  569. </style>