pie1.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="data_body">
  3. <div style="width: 100%; height: 100%">
  4. <div id="charts_canvas" class="echart" style="width: 100%; height: 100%"></div>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. loginArray: {
  12. type: Array
  13. },
  14. },
  15. data() {
  16. return {
  17. chartObj: null,
  18. ooption: {
  19. xdata: [],
  20. type: [],
  21. },
  22. option: {
  23. tooltip: {
  24. trigger: 'item'
  25. },
  26. series: [
  27. {
  28. type: 'pie',
  29. radius: ['80%', '100%'],
  30. avoidLabelOverlap: false,
  31. itemStyle: {
  32. borderRadius: 10,
  33. borderColor: '#fff',
  34. borderWidth: 2
  35. },
  36. label: {
  37. show: false,
  38. position: 'center',
  39. formatter: '{b}\n{c}'
  40. },
  41. emphasis: {
  42. label: {
  43. show: true,
  44. fontSize: 25,
  45. formatter: '{c}'
  46. }
  47. },
  48. labelLine: {
  49. show: false
  50. },
  51. hoverOffset: 0, // 设置鼠标悬停时不放大
  52. data: [
  53. { value: 10, name: '进行中', itemStyle: { normal: { color: '#3673e8' } } },
  54. { value: 8, name: '未发布', itemStyle: { normal: { color: '#61b8ff' } } },
  55. { value: 6, name: '已完成', itemStyle: { normal: { color: '#96d8a8' } } },
  56. { value: 7, name: '逾期', itemStyle: { normal: { color: '#f5b763' } } },
  57. ]
  58. }
  59. ]
  60. },
  61. };
  62. },
  63. methods: {
  64. setChart(array) {
  65. // 雷达图显示的标签
  66. let newPromise = new Promise((resolve) => {
  67. resolve();
  68. });
  69. //然后异步执行echarts的初始化函数
  70. newPromise.then(() => {
  71. const chartObj = this.$echarts.init(
  72. this.$el.querySelector("#charts_canvas")
  73. );
  74. // this.option.series[0].data = array;
  75. // 初始化雷达图
  76. this.chartObj = chartObj;
  77. this.chartObj.setOption(this.option);
  78. });
  79. },
  80. setJson(array) {
  81. this.ooption = {
  82. xdata: [],
  83. sdata: [],
  84. max: 0
  85. }
  86. if (!this.chartObj) {
  87. this.setChart(array);
  88. } else {
  89. this.option.series[0].data = array;
  90. this.chartObj.setOption(this.option);
  91. }
  92. }
  93. },
  94. watch: {
  95. loginArray: {
  96. immediate: true,
  97. deep: true,
  98. handler(newValue, oldValue) {
  99. this.setJson(newValue)
  100. this.$forceUpdate();
  101. },
  102. },
  103. },
  104. mounted() {
  105. this.setJson(this.loginArray)
  106. var _this = this;
  107. window.addEventListener("resize", () => {
  108. if (_this.chartObj) {
  109. _this.chartObj.resize();
  110. }
  111. });
  112. },
  113. };
  114. </script>
  115. <style scoped>
  116. .data_body {
  117. height: 100%;
  118. /* display: flex; */
  119. position: relative;
  120. border-radius: 5px;
  121. /* border: 1px solid #eee; */
  122. margin: 0 auto;
  123. box-sizing: border-box;
  124. padding: 0;
  125. width: 100%;
  126. /* background: #fff; */
  127. }
  128. </style>