coverageRateEcharts.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="coverageRateEcharts" id="coverageRateEcharts-box">
  3. </div>
  4. </template>
  5. <script>
  6. import {
  7. securityIndexStatisticsCheckOverlap,
  8. } from '@/api/safetyCheck/index'
  9. import echarts from 'echarts'
  10. export default {
  11. name: 'coverageRateEcharts',
  12. props:{
  13. propsData:{},
  14. },
  15. data(){
  16. return{
  17. newData:{},
  18. }
  19. },
  20. created(){
  21. },
  22. mounted(){
  23. this.securityIndexStatisticsCheckOverlap();
  24. },
  25. methods:{
  26. securityIndexStatisticsCheckOverlap(){
  27. let obj = {
  28. source:this.propsData.source,
  29. schoolAdmin:this.propsData.schoolAdmin,
  30. deptId:this.propsData.deptId,
  31. subIds:this.propsData.subIds,
  32. }
  33. securityIndexStatisticsCheckOverlap(obj).then(response => {
  34. this.$set(this,'newData',{
  35. notCheckRatio:parseInt(response.data.notCheckRatio),
  36. checkRatio:parseInt(response.data.checkRatio),
  37. subNum:parseInt(response.data.subNum),
  38. });
  39. this.$nextTick(()=>{
  40. this.eCharts(this.newData);
  41. })
  42. });
  43. },
  44. //eCharts方法
  45. eCharts(newData){
  46. let myChart = this.$echarts.init(document.getElementById('coverageRateEcharts-box'));
  47. const datalist= [
  48. { value: newData.notCheckRatio, name: '未检查' },
  49. { value: newData.checkRatio, name: '已检查' },
  50. ]
  51. let option = {
  52. legend:[
  53. {
  54. data: ['未检查'],
  55. orient: 'vertical',
  56. itemWidth: 12,
  57. itemHeight: 12,
  58. left: '60%',
  59. icon: 'circle',
  60. top: "38%",
  61. formatter: (name) => {
  62. var total = 0;
  63. var target;
  64. var rate;
  65. for (var i = 0; i < datalist.length; i++) {
  66. total += datalist[i].value;
  67. if (datalist[i].name == '未检查') {
  68. target = datalist[i].value;
  69. }
  70. rate = (target / total * 100).toFixed(2)
  71. }
  72. return `{one|${name}} {two|${rate}%}`;
  73. },
  74. textStyle: {
  75. color: '#000',
  76. rich: {
  77. one: {
  78. color: '#333333',
  79. fontSize: 12,
  80. padding: [0, 5, 0, 0],
  81. },
  82. two: {
  83. color: '#FFA200',
  84. fontSize: 14,
  85. },
  86. },
  87. },
  88. },
  89. {
  90. data: ['已检查'],
  91. orient: 'vertical',
  92. itemWidth: 12,
  93. itemHeight: 12,
  94. left: '60%',
  95. icon: 'circle',
  96. top: "54%",
  97. formatter: (name) => {
  98. var total = 0;
  99. var target;
  100. var rate;
  101. for (var i = 0; i < datalist.length; i++) {
  102. total += datalist[i].value;
  103. if (datalist[i].name == name) {
  104. target = datalist[i].value;
  105. }
  106. rate = (target / total * 100).toFixed(2)
  107. }
  108. return `{one|${name}} {two|${rate}%}`;
  109. },
  110. textStyle: {
  111. color: '#000',
  112. rich: {
  113. one: {
  114. color: '#333333',
  115. fontSize: 12,
  116. padding: [0, 5, 0, 0],
  117. },
  118. two: {
  119. color: '#0183FA',
  120. fontSize: 14,
  121. },
  122. },
  123. },
  124. }
  125. ],
  126. title: [
  127. {
  128. text: '实验室',
  129. subtext: newData.subNum+'间',
  130. textStyle: {
  131. fontSize: 12,
  132. color: "#333333"
  133. },
  134. subtextStyle: {
  135. fontSize: 16,
  136. color: '#333333'
  137. },
  138. textAlign: "center",
  139. x: '24%',
  140. y: '38%',
  141. }
  142. ],
  143. color:[ '#FFA200','#0183FA'],
  144. series: [
  145. {
  146. name: '检查覆盖率',
  147. type: 'pie',
  148. radius: ['48%', '80%'],
  149. center: ['26%', '50%'],
  150. avoidLabelOverlap: false,
  151. padAngle: 10,
  152. itemStyle: {
  153. borderColor: '#FFF',
  154. borderWidth: 3,
  155. },
  156. label: {
  157. show: false,
  158. position: 'center'
  159. },
  160. emphasis: {
  161. label: {
  162. show: false,
  163. fontSize: 40,
  164. fontWeight: 'bold'
  165. }
  166. },
  167. labelLine: {
  168. show: false
  169. },
  170. data:datalist
  171. }
  172. ]
  173. };
  174. myChart.setOption(option);
  175. },
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. .coverageRateEcharts{
  181. width: 366px;
  182. height: 175px;
  183. }
  184. </style>