getPieView.vue 2.7 KB

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