getPieView.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="pieView">
  3. <div
  4. style="
  5. height: 14%;
  6. line-height: 30px;
  7. text-align: left;
  8. padding-left: 10px;
  9. color: white;
  10. "
  11. >
  12. {{ info.config.title || "" }}
  13. </div>
  14. <div
  15. style="width: 100%; height: 86%; display: inline-block; overflow: hidden"
  16. v-show="showChart"
  17. >
  18. <div
  19. :id="info.config.idSelector"
  20. style="width: 100%; height: 95%; overflow: hidden"
  21. ></div>
  22. </div>
  23. <div
  24. style="
  25. background: #061237;
  26. width: 100%;
  27. height: 70%;
  28. display: flex;
  29. justify-content: cne;
  30. justify-content: center;
  31. align-items: center;
  32. "
  33. v-if="!showChart"
  34. >
  35. <div style="color: #c7c7c7">目前无数据</div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import * as echarts from "echarts";
  41. export default {
  42. data() {
  43. return {
  44. showChart: true,
  45. };
  46. },
  47. props: {
  48. info: {
  49. type: Object,
  50. default: {},
  51. },
  52. },
  53. mounted() {
  54. let this_ = this;
  55. this.$nextTick(() => {
  56. this_.getMiddleLeft();
  57. });
  58. },
  59. methods: {
  60. getMiddleLeft() {
  61. let chartDom = document.getElementById(this.info.config.idSelector);
  62. var myChart = echarts.init(chartDom);
  63. const radius = window.innerWidth > 1600 ? "55%" : "45%";
  64. let inData = this.info.data;
  65. let num = 0;
  66. for (let i in inData) {
  67. num += inData[i].value;
  68. }
  69. if (num == 0) {
  70. this.showChart = false;
  71. } else {
  72. this.showChart = true;
  73. }
  74. var option;
  75. option = {
  76. title: {
  77. show: true,
  78. left: "center",
  79. textStyle: {
  80. color: "#fff",
  81. fontSize: 20,
  82. fontWeight: "600",
  83. },
  84. },
  85. color: this.info.color,
  86. tooltip: {
  87. trigger: "item",
  88. formatter: "{d}%",
  89. },
  90. label: {
  91. formatter: "{b}\n({d}%)",
  92. edgeDistance: "20%",
  93. },
  94. legend: {
  95. show: true,
  96. z: 3,
  97. left: "right",
  98. textStyle: {
  99. color: "#fff",
  100. },
  101. },
  102. series: [
  103. {
  104. type: "pie",
  105. radius: radius,
  106. center: ["50%", "50%"],
  107. data: this.info.data,
  108. emphasis: {
  109. itemStyle: {
  110. shadowBlur: 10,
  111. shadowOffsetX: 0,
  112. shadowColor: "rgba(0, 0, 0, 0.5)",
  113. },
  114. },
  115. labelLine: {
  116. distanceToLabelLine: 0,
  117. },
  118. },
  119. ],
  120. };
  121. myChart.setOption(option);
  122. },
  123. },
  124. watch: {
  125. info: {
  126. handler(newVal, oldVal) {
  127. this.getMiddleLeft();
  128. },
  129. deep: true,
  130. },
  131. },
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. .pieView {
  136. width: 100%;
  137. height: 100%;
  138. overflow: hidden;
  139. background-color: rgba(6, 30, 93, 0.5);
  140. }
  141. </style>