index.vue 16 KB

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