cake.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!-- 饼图统计 -->
  2. <template>
  3. <div>
  4. <boxTop :title="title" />
  5. <div class="cakeBox flex">
  6. <div class="chartsdom" id="cake"></div>
  7. <div class="panel">
  8. <div class="panelitem flex space_around">
  9. <div v-if="data.年移栽数量">
  10. <div class="number">{{ data.年移栽数量 }}</div>
  11. <div class="text">
  12. <img class="img1" src="../../assets/img/rectangle.png" alt="" />
  13. 年移栽数量
  14. </div>
  15. </div>
  16. <div v-if="data.年移栽面积">
  17. <div class="number">{{ data.年移栽面积 }}</div>
  18. <div class="text">
  19. <img
  20. class="img1"
  21. src="../../assets/img/rectangle.png"
  22. alt=""
  23. />年移栽面积
  24. </div>
  25. </div>
  26. </div>
  27. <div class="panelitem">
  28. <div v-if="data.移栽区域数" class="flex space_between secondItem">
  29. <img class="img" src="../../assets/img/tree.png" alt="" />
  30. <div>移栽区域数</div>
  31. <div>{{ data.移栽区域数 }}</div>
  32. </div>
  33. <div v-if="data.烟农数量" class="flex space_between secondItem">
  34. <img class="img" src="../../assets/img/head.png" alt="" />
  35. <div>烟农数量</div>
  36. <div>{{ data.烟农数量 }}</div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import boxTop from '@/components/boxTop/index.vue'
  45. export default {
  46. data() {
  47. return {
  48. option: null,
  49. information: {},
  50. }
  51. },
  52. components: {
  53. boxTop,
  54. },
  55. props: {
  56. data: {
  57. type: Object,
  58. },
  59. title: {
  60. type: String,
  61. default: ``,
  62. },
  63. titleEn: {
  64. type: String,
  65. default: `Tongren Tobacco Planting Digital Management Platform`,
  66. },
  67. },
  68. async mounted() {
  69. this.getEchart()
  70. },
  71. watch: {
  72. data() {
  73. this.getEchart()
  74. },
  75. },
  76. methods: {
  77. getEchart() {
  78. let myChart = echarts.init(document.getElementById(`cake`))
  79. const title = `目标完成率`
  80. const value = this.data.目标完成率
  81. const splitLineLength = `19%`
  82. const splitLineDistance = -5
  83. const splitLineWidth = 2
  84. const int = value.toFixed(1).split(`.`)[0]
  85. const float = value.toFixed(1).split(`.`)[1]
  86. this.option = {
  87. title: {
  88. text: `{a|` + int + `}{b|.` + float + `%}\n{c|` + title + `}`,
  89. x: `center`,
  90. y: `center`,
  91. textStyle: {
  92. rich: {
  93. a: {
  94. fontSize: 36,
  95. color: `#fff`,
  96. },
  97. b: {
  98. fontSize: 20,
  99. color: `#96A2BC`,
  100. padding: [2, 0, 0, 0],
  101. },
  102. c: {
  103. fontSize: 16,
  104. color: `#96A2BC`,
  105. padding: [2, 0, 0, 0],
  106. },
  107. },
  108. },
  109. },
  110. series: [
  111. {
  112. type: `pie`,
  113. radius: [`84%`, `70%`],
  114. silent: true,
  115. clockwise: false,
  116. startAngle: 90,
  117. z: 0,
  118. zlevel: 0,
  119. data: [
  120. {
  121. value: value,
  122. itemStyle: {
  123. color: {
  124. type: `linear`,
  125. x: 1,
  126. y: 0,
  127. x2: 0,
  128. y2: 1,
  129. colorStops: [
  130. {
  131. offset: 0,
  132. color: `#DFFFFF`, // 0% 处的颜色
  133. },
  134. {
  135. offset: 1,
  136. color: `#0E7E7D`, // 100% 处的颜色
  137. },
  138. ],
  139. global: false, // 缺省为 false
  140. },
  141. },
  142. label: {
  143. show: false,
  144. },
  145. },
  146. {
  147. value: 100 - value,
  148. label: {
  149. show: false,
  150. },
  151. itemStyle: {
  152. normal: {
  153. color: `rgba(15, 31, 52,1)`,
  154. },
  155. },
  156. },
  157. ],
  158. },
  159. {
  160. name: ``,
  161. type: `gauge`,
  162. radius: `88%`,
  163. center: [`50%`, `50%`],
  164. startAngle: 0,
  165. endAngle: 360,
  166. splitNumber: 100,
  167. hoverAnimation: true,
  168. axisTick: {
  169. show: false,
  170. },
  171. splitLine: {
  172. length: splitLineLength,
  173. distance: splitLineDistance,
  174. lineStyle: {
  175. width: splitLineWidth,
  176. color: `#000`,
  177. },
  178. },
  179. axisLabel: {
  180. show: false,
  181. },
  182. pointer: {
  183. show: false,
  184. },
  185. axisLine: {
  186. show: false,
  187. },
  188. },
  189. {
  190. name: `外边框`,
  191. type: `pie`,
  192. clockwise: false, // 顺时加载
  193. emphasis: {
  194. scale: false, // 鼠标移入变大
  195. },
  196. center: [`50%`, `50%`],
  197. radius: [`88%`, `88%`],
  198. label: {
  199. show: false,
  200. },
  201. data: [
  202. {
  203. value: 0,
  204. name: ``,
  205. itemStyle: {
  206. borderWidth: 2,
  207. borderColor: `#24FFFD`,
  208. },
  209. },
  210. ],
  211. },
  212. ],
  213. }
  214. myChart.setOption(this.option)
  215. },
  216. },
  217. }
  218. </script>
  219. <style lang="less" scoped>
  220. .cakeBox {
  221. width: 401px;
  222. height: 234px;
  223. .chartsdom {
  224. width: 80%;
  225. height: 90%;
  226. }
  227. .panel {
  228. width: 80%;
  229. height: 80%;
  230. .panelitem {
  231. border-top: 2px solid rgba(255, 255, 255, 0.3);
  232. box-sizing: border-box;
  233. height: 50%;
  234. margin: 0 10px;
  235. .secondItem {
  236. font-size: 16px;
  237. margin: 21px 0;
  238. }
  239. }
  240. }
  241. }
  242. .flex {
  243. display: flex;
  244. }
  245. .img {
  246. height: 25px;
  247. margin-right: 3px;
  248. }
  249. .img1 {
  250. height: 17px;
  251. width: 3px;
  252. margin-right: 3px;
  253. }
  254. .l-height {
  255. line-height: 100%;
  256. }
  257. .space_around {
  258. justify-content: space-around;
  259. align-items: center;
  260. }
  261. .space_between {
  262. justify-content: space-between;
  263. align-items: center;
  264. }
  265. .number {
  266. font-size: 22px;
  267. padding: 4px 0;
  268. margin: 3px 0;
  269. }
  270. .text {
  271. font-size: 14px;
  272. color: #888888;
  273. display: flex;
  274. justify-content: center;
  275. align-items: center;
  276. }
  277. .column_reverse {
  278. flex-direction: column-reverse;
  279. }
  280. </style>