index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="chart-wrap">
  3. <v-chart autoresize :option="option"/>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from 'echarts'
  8. import {chartDlsdxl, chartDlydts} from '@/api/dashboard-json'
  9. export default {
  10. name: 'Dlydtssx',
  11. data() {
  12. return {
  13. arrMap: [],
  14. option: {}
  15. }
  16. },
  17. created() {
  18. this.getOption()
  19. },
  20. methods: {
  21. async getOption() {
  22. const res = await chartDlydts()
  23. window['tis'] = this;
  24. if (res?.code === 200) {
  25. const arrMap = []
  26. // const max =
  27. res.info.xaxis.forEach((item, index) => {
  28. const valItem = {
  29. name: item,
  30. used: res.info.series[0].data[index],
  31. value: res.info.series[0].data[index],
  32. total: res.info.series[1].data[index]
  33. }
  34. arrMap.push(valItem)
  35. })
  36. arrMap.forEach(item => {
  37. if (item.used > item.total) {
  38. item.used = item.total * 1.08
  39. }
  40. })
  41. this.arrMap = arrMap
  42. }
  43. let data = [{
  44. name: '第一季度',
  45. used: 100,
  46. total: 100
  47. }, {
  48. name: '第二季度',
  49. used: 10,
  50. total: 100
  51. }, {
  52. name: '第三季度',
  53. used: 10,
  54. total: 100
  55. }, {
  56. name: '第四季度',
  57. used: 10,
  58. total: 100
  59. }]
  60. data = this.arrMap.reverse()
  61. window['t_data'] = data
  62. const colors = [
  63. [
  64. new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(82, 113, 195)'}, {
  65. offset: 1,
  66. color: 'rgb(120, 142, 237)'
  67. }], false),
  68. new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(81, 129, 192)'}, {
  69. offset: 1,
  70. color: 'rgb(123, 148, 234)'
  71. }], false),
  72. new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(89, 137, 188)'}, {
  73. offset: 1,
  74. color: 'rgb(113, 173, 229)'
  75. }], false),
  76. new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(88, 166, 191)'}, {
  77. offset: 1,
  78. color: 'rgb(128, 230, 226)'
  79. }], false)
  80. ],
  81. ['rgb(41, 73, 110)',
  82. 'rgb(41, 73, 110)',
  83. 'rgb(41, 73, 110)',
  84. 'rgb(41, 73, 110)'
  85. ]
  86. ]
  87. const series = []
  88. const yAxis = []
  89. for (let i = data.length - 1; i >= 0 ; i--) {
  90. series.push({
  91. name: '',
  92. type: 'pie',
  93. clockWise: false, // 顺时加载
  94. hoverAnimation: false, // 鼠标移入变大
  95. radius: [90 - i * 15 + '%', 84 - i * 15 + '%'],
  96. center: ['45%', '50%'],
  97. label: {
  98. show: false
  99. },
  100. itemStyle: {
  101. label: {
  102. show: false
  103. },
  104. labelLine: {
  105. show: false
  106. },
  107. borderRadius: 60 // 设置每一段子项目的圆角
  108. },
  109. data: [
  110. {
  111. value: data[i].used * (3 / 4),
  112. name: data[i].name
  113. },
  114. {
  115. value: (data[i].total - data[i].used) + data[i].used * (1 / 4),
  116. name: data[i].name,
  117. itemStyle: {
  118. color: 'transparent',
  119. borderRadius: 60 // 设置每一段子项目的圆角
  120. },
  121. tooltip: {
  122. show: false
  123. },
  124. hoverAnimation: false
  125. }
  126. ]
  127. })
  128. series.push({
  129. name: null,
  130. type: 'pie',
  131. silent: true,
  132. z: 1,
  133. clockWise: false, // 顺时加载
  134. hoverAnimation: false, // 鼠标移入变大
  135. radius: [90 - i * 15 + '%', 84 - i * 15 + '%'],
  136. center: ['45%', '50%'],
  137. label: {
  138. show: false
  139. },
  140. itemStyle: {
  141. label: {
  142. show: false
  143. },
  144. labelLine: {
  145. show: false
  146. },
  147. borderRadius: 60 // 设置每一段子项目的圆角
  148. },
  149. data: [
  150. {
  151. value: 7.5,
  152. itemStyle: {
  153. color: colors[1][i]
  154. },
  155. tooltip: {
  156. show: false
  157. },
  158. hoverAnimation: false
  159. },
  160. {
  161. value: 2.5,
  162. itemStyle: {
  163. color: 'rgba(0,0,0,0)',
  164. borderWidth: 0,
  165. borderRadius: 60 // 设置每一段子项目的圆角
  166. },
  167. tooltip: {
  168. show: false
  169. },
  170. hoverAnimation: false
  171. }
  172. ]
  173. })
  174. yAxis.push(((data[i].used / data[i].total) * 100).toFixed(0) + '%')
  175. }
  176. this.option = {
  177. color: colors[0],
  178. legend: {
  179. show: true,
  180. icon: 'reac',
  181. top: '0%',
  182. left: '65%',
  183. width: 10,
  184. height: 10000,
  185. orient: 'horizontal',
  186. data: name,
  187. selectedMode: false,
  188. // orient: 'vertical',
  189. formatter: (name) => {
  190. const findItem = data.find(item => item.name === name)
  191. if (findItem) {
  192. if (findItem.total <= 0) {
  193. return name + ' ' + findItem.total + '%'
  194. } else {
  195. const per = ((findItem.value / findItem.total) * 100).toFixed(0)
  196. return `${name} ${per}%`
  197. }
  198. } else {
  199. return name
  200. }
  201. },
  202. textStyle: {
  203. fontSize: this.EchartfontSize(10),
  204. color: 'rgba(255,255,255,0.8)',
  205. }
  206. },
  207. tooltip: {
  208. show: false,
  209. trigger: 'item',
  210. formatter: '{a}<br>{b}:{c}({d}%)'
  211. },
  212. grid: {
  213. top: '3%',
  214. left: '45%',
  215. width: '40%',
  216. height: '30%',
  217. containLabel: true
  218. },
  219. yAxis: [{
  220. type: 'category',
  221. inverse: false,
  222. axisLine: {
  223. show: false
  224. },
  225. axisTick: {
  226. show: false
  227. },
  228. axisLabel: {
  229. formatter: (name, index) => {
  230. return `${this.arrMap[index].value}/${this.arrMap[index].total}`
  231. },
  232. interval: 0,
  233. inside: true,
  234. textStyle: {
  235. color: 'rgba(255,255,255,0.8)',
  236. fontSize: this.EchartfontSize(12)
  237. },
  238. show: true
  239. },
  240. data: yAxis
  241. }],
  242. xAxis: [{
  243. show: false
  244. }],
  245. series: series
  246. }
  247. }
  248. }
  249. }
  250. </script>
  251. <style scoped lang="scss">
  252. $xHeight: 120px;
  253. .chart-wrap {
  254. width: 100%;
  255. height: 100%;
  256. .left-bar {
  257. width: 35px;
  258. display: inline-block;
  259. }
  260. .right-conent {
  261. width: calc(100% - 35px);
  262. height: 100%;
  263. display: grid;
  264. grid-template-columns: 1fr 1fr 1fr 1fr;
  265. grid-template-rows: auto $xHeight;
  266. }
  267. }
  268. </style>