index.vue 10 KB

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