index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="chart-wrap">
  3. <div class="l-coner">
  4. <v-chart autoresize :option="option"/>
  5. </div>
  6. <div class="r-coner">
  7. <div class="c-item">{{ arrMap['单元'].per }}%</div>
  8. <div class="c-item">{{ arrMap['变电所'].per }}%</div>
  9. <div class="c-item">{{ arrMap['配电所'].per }}%</div>
  10. <div class="c-item">{{ arrMap['电源线'].per }}%</div>
  11. <div class="c-item">{{ arrMap['箱变'].per }}%</div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import * as echarts from 'echarts'
  17. import {chartQbdlsbxjdx} from '@/api/dashboard-json'
  18. export default {
  19. name: 'QbDlsbxjdx',
  20. data() {
  21. return {
  22. option: {},
  23. arrMap: {}
  24. }
  25. },
  26. created() {
  27. this.getOption()
  28. },
  29. methods: {
  30. async getOption() {
  31. window['tis'] = this
  32. let keys = []
  33. const maxs = []
  34. const values = []
  35. const res = await chartQbdlsbxjdx()
  36. if (res?.code === 200) {
  37. keys = res?.info.xaxis
  38. res?.info.xaxis.forEach((key, index) => {
  39. maxs.push(res.info.series[0].data[index])
  40. values.push(res.info.series[1].data[index])
  41. const keyMap = {
  42. [res?.info.series[0].name]: res.info.series[0].data[index],
  43. [res?.info.series[1].name]: res.info.series[1].data[index],
  44. per: (res.info.series[1].data[index] * 100 / res.info.series[0].data[index]).toFixed(0)
  45. }
  46. this.arrMap[key] = keyMap
  47. })
  48. }
  49. window['max'] = maxs.reverse()
  50. window['values'] = values.reverse()
  51. const CubeLeft = echarts.graphic.extendShape({
  52. shape: {
  53. x: 0,
  54. y: 0
  55. },
  56. buildPath: (ctx, shape) => {
  57. const yAxisPoint = shape.yAxisPoint
  58. const c0 = [shape.x, shape.y]
  59. const c1 = [shape.x + 9, shape.y - 9]
  60. const c2 = [yAxisPoint[0] + 9, yAxisPoint[1] - 9]
  61. const c3 = [yAxisPoint[0], yAxisPoint[1]]
  62. ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath()
  63. }
  64. })
  65. const CubeRight = echarts.graphic.extendShape({
  66. shape: {
  67. x: 0,
  68. y: 0
  69. },
  70. buildPath: function(ctx, shape) {
  71. const yAxisPoint = shape.yAxisPoint
  72. const c1 = [shape.x, shape.y]
  73. const c2 = [yAxisPoint[0], yAxisPoint[1]]
  74. const c3 = [yAxisPoint[0] + 9, yAxisPoint[1] + 18]
  75. const c4 = [shape.x + 9, shape.y + 18]
  76. ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath()
  77. }
  78. })
  79. const CubeTop = echarts.graphic.extendShape({
  80. shape: {
  81. x: 0,
  82. y: 0
  83. },
  84. buildPath: function(ctx, shape) {
  85. const c1 = [shape.x, shape.y]
  86. const c2 = [shape.x + 9, shape.y + 18]
  87. const c3 = [shape.x + 18, shape.y + 9]
  88. const c4 = [shape.x + 9, shape.y - 9]
  89. ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath()
  90. }
  91. })
  92. echarts.graphic.registerShape('CubeLeft', CubeLeft)
  93. echarts.graphic.registerShape('CubeRight', CubeRight)
  94. echarts.graphic.registerShape('CubeTop', CubeTop)
  95. // const MAX = [100, 220, 200, 150, 200]
  96. const MAX = maxs
  97. // const VALUE = [20, 10, 30, 50, 150]
  98. const VALUE = values
  99. const NAMES = ['箱变', '电源线', '配电所', '变电所', '单元']
  100. this.option = {
  101. grid: {
  102. left: 0,
  103. right: 0,
  104. bottom: 0,
  105. top: 0,
  106. width: '100%',
  107. height: '100%',
  108. containLabel: true
  109. },
  110. yAxis: {
  111. type: 'category',
  112. data: NAMES,
  113. show: false,
  114. axisLine: {
  115. show: false,
  116. lineStyle: {
  117. color: 'white'
  118. }
  119. },
  120. offset: 0,
  121. axisTick: {
  122. show: false,
  123. length: 9,
  124. alignWithLabel: false,
  125. lineStyle: {
  126. color: '#7DFFFD'
  127. }
  128. },
  129. axisLabel: {
  130. fontSize: `this.EchartfontSize(10)`
  131. }
  132. },
  133. xAxis: {
  134. type: 'value',
  135. axisLine: {
  136. show: false,
  137. lineStyle: {
  138. color: 'white'
  139. }
  140. },
  141. splitLine: {
  142. show: false
  143. },
  144. axisTick: {
  145. show: false
  146. },
  147. axisLabel: {
  148. show: true,
  149. fontSize: this.EchartfontSize(10)
  150. }
  151. },
  152. series: [{
  153. type: 'custom',
  154. renderItem: function(params, api) {
  155. const location = api.coord([api.value(0), api.value(1)])
  156. return {
  157. type: 'group',
  158. children: [{
  159. type: 'CubeLeft',
  160. shape: {
  161. api,
  162. xValue: api.value(0),
  163. yValue: api.value(1),
  164. x: location[0],
  165. y: location[1],
  166. yAxisPoint: api.coord([0, api.value(1)])
  167. },
  168. style: {
  169. fill: 'rgb(19, 39, 46) '
  170. }
  171. }, {
  172. type: 'CubeRight',
  173. shape: {
  174. api,
  175. xValue: api.value(0),
  176. yValue: api.value(1),
  177. x: location[0],
  178. y: location[1],
  179. yAxisPoint: api.coord([0, api.value(1)])
  180. },
  181. style: {
  182. fill: 'rgb(19, 39, 46) '
  183. }
  184. }, {
  185. type: 'CubeTop',
  186. shape: {
  187. api,
  188. xValue: api.value(0),
  189. yValue: api.value(1),
  190. x: location[0],
  191. y: location[1],
  192. yAxisPoint: api.coord([0, api.value(1)])
  193. },
  194. style: {
  195. fill: 'rgb(19, 39, 46)'
  196. }
  197. }]
  198. }
  199. },
  200. data: MAX
  201. },
  202. {
  203. type: 'custom',
  204. renderItem: (params, api) => {
  205. const location = api.coord([api.value(0), api.value(1)])
  206. return {
  207. type: 'group',
  208. children: [{
  209. type: 'CubeLeft',
  210. shape: {
  211. api,
  212. xValue: api.value(0),
  213. yValue: api.value(1),
  214. x: location[0],
  215. y: location[1],
  216. yAxisPoint: api.coord([0, api.value(1)])
  217. },
  218. style: {
  219. fill: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  220. offset: 0,
  221. color: '#50B9E0'
  222. },
  223. {
  224. offset: 1,
  225. color: '#88DDF2'
  226. }
  227. ])
  228. }
  229. }, {
  230. type: 'CubeRight',
  231. shape: {
  232. api,
  233. xValue: api.value(0),
  234. yValue: api.value(1),
  235. x: location[0],
  236. y: location[1],
  237. yAxisPoint: api.coord([0, api.value(1)])
  238. },
  239. style: {
  240. fill: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  241. offset: 0,
  242. color: '#399AB2'
  243. },
  244. {
  245. offset: 1,
  246. color: '#6BCAD9'
  247. }
  248. ])
  249. }
  250. }, {
  251. type: 'CubeTop',
  252. shape: {
  253. api,
  254. xValue: api.value(0),
  255. yValue: api.value(1),
  256. x: location[0],
  257. y: location[1],
  258. yAxisPoint: api.coord([0, api.value(1)])
  259. },
  260. style: {
  261. fill: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  262. offset: 0,
  263. color: 'rgba(127,217,254,0.78)'
  264. },
  265. {
  266. offset: 1,
  267. color: '#7FD9FE'
  268. }
  269. ])
  270. }
  271. }]
  272. }
  273. },
  274. data: VALUE
  275. },
  276. {
  277. type: 'bar',
  278. label: {
  279. normal: {
  280. show: true,
  281. position: [0, '10%'],
  282. formatter: (e) => {
  283. return e.name
  284. },
  285. fontSize: this.EchartfontSize(14),
  286. color: '#fff'
  287. }
  288. },
  289. itemStyle: {
  290. color: 'transparent'
  291. },
  292. data: VALUE
  293. },
  294. {
  295. type: 'bar',
  296. label: {
  297. normal: {
  298. show: true,
  299. position: ['80%', '-100%'],
  300. formatter: (e) => {
  301. const ret = `${values[e.dataIndex]}/${maxs[e.dataIndex]}`
  302. return ret
  303. },
  304. fontSize: this.EchartfontSize(14),
  305. color: '#fff'
  306. }
  307. },
  308. itemStyle: {
  309. color: 'transparent'
  310. },
  311. data: MAX,
  312. zlevel: 2
  313. }
  314. ]
  315. }
  316. }
  317. }
  318. }
  319. </script>
  320. <style scoped lang="scss">
  321. .chart-wrap {
  322. width: 100%;
  323. height: 100%;
  324. display: flex;
  325. .l-coner {
  326. flex-grow: 1;
  327. width: 100%;
  328. height: 100%;
  329. }
  330. .r-coner {
  331. width: 4vw;
  332. height: 100%;
  333. flex-shrink: 0;
  334. display: flex;
  335. flex-direction: column;
  336. align-items: center;
  337. justify-content: space-around;
  338. font: normal 0.6vw hxb;
  339. .c-item {
  340. color: #91FFFF;
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. flex: 1;
  345. flex-shrink: 0;
  346. width: 100%;
  347. height: 100%;
  348. background-image: url("/static/images/qianbian_circular@2x.png");
  349. background-repeat: no-repeat;
  350. background-position: center;
  351. background-size: contain;
  352. }
  353. }
  354. }
  355. </style>