index.vue 5.8 KB

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