pie2.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <el-row >
  3. <div
  4. id="index6"
  5. class="line"
  6. style="width:110%;height:260px;margin:-30px 0 0 40px;"
  7. ></div>
  8. </el-row>
  9. </template>
  10. <script>
  11. import * as echarts from 'echarts';
  12. export default {
  13. props: ["resData"],
  14. data() {
  15. return {
  16. data:[]
  17. };
  18. },
  19. watch: {
  20. resData(val,old){
  21. this.data = val
  22. this.getData()
  23. }
  24. },
  25. methods: {
  26. getData() {
  27. let total = this.data.pie[0].value + this.data.pie[1].value + this.data.pie[2].value + this.data.pie[3].value + this.data.pie[4].value
  28. let zaixianlv = this.data.zaixianlv
  29. let myChart = echarts.init(document.getElementById("index6"));
  30. let option = {
  31. color: [
  32. '#8082D6',
  33. '#FFC46D',
  34. '#E8684A',
  35. '#4EBA60',
  36. '#8082D6'
  37. ],
  38. tooltip: {
  39. trigger: 'item'
  40. },
  41. grid: {
  42. left: '-10%',
  43. containLabel: true
  44. },
  45. title: {
  46. text: "",
  47. text: zaixianlv + '%',
  48. textStyle: {
  49. color: '#E6EFFF',
  50. fontSize: 25
  51. },
  52. subtext: '设备在线率',
  53. subtextStyle: {
  54. color: '#E6EFFF',
  55. fontSize: 14
  56. },
  57. itemGap: 10, // 主副标题距离
  58. left: 'center',
  59. top: '42%'
  60. },
  61. legend: {
  62. orient: 'vertical',
  63. itemHeight: 8,
  64. itemWidth: 8,
  65. left:'20%',
  66. data: [
  67. {
  68. name: this.data.pie[0].name,
  69. icon: 'circle',
  70. },
  71. {
  72. name: this.data.pie[1].name,
  73. icon: 'circle',
  74. },
  75. {
  76. name: this.data.pie[2].name,
  77. icon: 'circle',
  78. },
  79. {
  80. name: this.data.pie[3].name,
  81. icon: 'circle',
  82. },
  83. {
  84. name: this.data.pie[4].name,
  85. icon: 'circle',
  86. }
  87. ],
  88. top: '20%',
  89. left: 'left',
  90. textStyle: {
  91. color: "#FFF"
  92. }
  93. },
  94. series: [
  95. {
  96. name: '',
  97. type: 'pie',
  98. radius: ['40%', '55%'],
  99. avoidLabelOverlap: false,
  100. itemStyle: {
  101. normal: {
  102. label: {
  103. show: true,
  104. position: 'outer',
  105. fontSize: 18,
  106. fontWeight: 'bold',
  107. align: "left",
  108. formatter: function (p) { //指示线对应文字,说明文字
  109. return ((p.data.value/total) * 100).toFixed(2) + '%';
  110. }
  111. },
  112. labelLine: { //指示线状态
  113. show: true,
  114. smooth: 0.8,
  115. length: 4,
  116. length2: 20
  117. }
  118. }
  119. },
  120. data: this.data.pie
  121. }
  122. ]
  123. };
  124. myChart.setOption(option);
  125. option && myChart.setOption(option);
  126. setTimeout(function () {
  127. window.onresize = function () {
  128. myChart.resize();
  129. };
  130. }, 200);
  131. },
  132. },
  133. };
  134. </script>