getPieView.vue 2.5 KB

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