finishPercentPie.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div :id="id" style="height: 100%;width:100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. data () {
  7. return {
  8. mychat: '',
  9. realPercent: 100,
  10. pieFinishPercent: 75,
  11. }
  12. },
  13. props:{
  14. id:{
  15. type: String
  16. },
  17. pieData:{
  18. type: Object,
  19. default: function(){
  20. return {total:175, value: 128}
  21. },
  22. },
  23. },
  24. mounted(){
  25. this.drawLine();
  26. },
  27. created(){
  28. this.realPercent = Math.round((this.pieData.value / this.pieData.total)* 100);
  29. this.pieFinishPercent = (this.realPercent / 100.00) * 75
  30. },
  31. methods:{
  32. drawLine(){
  33. let _this = this
  34. // 基于准备好的dom,初始化echarts实例
  35. this.myChart = this.$echarts.init(document.getElementById(this.id));
  36. this.myChart.setOption({
  37. title: {
  38. "text": '课堂总数 : ' + _this.pieData.total + '\n' + '完成数量 : ' + _this.pieData.value,
  39. "x": '50%',
  40. "y": '75%',
  41. "textAlign": "center",
  42. "textStyle": {
  43. "fontWeight": 'lighter',
  44. "fontSize": 11,
  45. "color": "#A9B2B8",
  46. },
  47. },
  48. series: [{
  49. "name": ' ',
  50. "type": 'pie',
  51. "radius": ['50%', '68.1%'],
  52. "avoidLabelOverlap": false,
  53. "startAngle": 225,
  54. "color": ["#fff", "transparent"],
  55. "hoverAnimation": false,
  56. "legendHoverLink": false,
  57. "label": {
  58. "normal": {
  59. "show": false,
  60. "position": 'center'
  61. },
  62. "emphasis": {
  63. "show": true,
  64. "textStyle": {
  65. "fontSize": '30',
  66. "fontWeight": 'bold'
  67. }
  68. }
  69. },
  70. "labelLine": {
  71. "normal": {
  72. "show": false
  73. }
  74. },
  75. "data": [{
  76. "value": 75,
  77. "name": '',
  78. "itemStyle": {
  79. normal: {
  80. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  81. offset: 0,
  82. color: "rgba(228, 233, 220, 0.14)" // 0% 处的颜色
  83. },{
  84. offset: 1,
  85. color: "rgba(228, 233, 220, 0.14)" // 100% 处的颜色
  86. }], false),
  87. label: {
  88. show: false
  89. },
  90. labelLine: {
  91. show: false
  92. }
  93. },
  94. }
  95. }, {
  96. "value": 25,
  97. "name": '',
  98. "itemStyle": {
  99. "normal": {
  100. color: 'rgba(0,0,0,0)'
  101. }
  102. }
  103. }]
  104. }, {
  105. "name": '',
  106. "type": 'pie',
  107. "radius": ['50%', '68.1%'],
  108. "avoidLabelOverlap": false,
  109. "startAngle": 225,
  110. "color": ["#fff", "transparent"],
  111. "hoverAnimation": false,
  112. "legendHoverLink": false,
  113. "z": 10,
  114. "label": {
  115. "normal": {
  116. "show": false,
  117. "position": 'center'
  118. },
  119. },
  120. "labelLine": {
  121. "normal": {
  122. "show": false
  123. }
  124. },
  125. "data": [{
  126. "name": _this.realPercent.toString(), //完成数实际值
  127. "value": _this.pieFinishPercent, // PIE完成数
  128. "label": {
  129. "normal": {
  130. "show": true,
  131. "formatter": '{b} %',
  132. "textStyle": {
  133. "fontSize": 20,
  134. "fontWeight": "100",
  135. "color": "#ffffff",
  136. },
  137. "position": "center"
  138. }
  139. },
  140. "itemStyle": {
  141. normal: {
  142. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  143. offset: 0,
  144. color: "rgba(228, 233, 220, 1)" // 0% 处的颜色
  145. },{
  146. offset: 1,
  147. color: "rgba(228, 233, 220, 0.5)" // 100% 处的颜色
  148. }], false),
  149. label: {
  150. show: false
  151. },
  152. labelLine: {
  153. show: false
  154. }
  155. },
  156. }
  157. }, {
  158. "name": '',
  159. "value": (100 - _this.pieFinishPercent), // PIE未完成数 100% 是75
  160. "itemStyle": {
  161. "normal": {
  162. color: 'rgba(0,0,0,0)'
  163. }
  164. }
  165. }]
  166. }]
  167. });
  168. },
  169. }
  170. }
  171. </script>
  172. <style>
  173. </style>