getPieView.vue 3.8 KB

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