pie1.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: true,
  38. position: 'center',
  39. // formatter: '{b}\n{c}'
  40. fontSize: 20,
  41. rich: {
  42. a: {
  43. fontSize: 30,
  44. },
  45. b: {
  46. lineHeight: 20,
  47. fontSize: 14,
  48. color: '#00000099'
  49. }
  50. }
  51. // formatter: function (params) {
  52. // console.log(params);
  53. // var sum = 0;
  54. // for (var i = 0; i < params.data.length; i++) {
  55. // sum += params.data[i].value;
  56. // }
  57. // return sum + '\n表单总数';
  58. // }
  59. },
  60. emphasis: {
  61. label: {
  62. show: true,
  63. fontSize: 20,
  64. rich: {
  65. a: {
  66. fontSize: 30,
  67. },
  68. b: {
  69. lineHeight: 20,
  70. fontSize: 14,
  71. color: '#00000099'
  72. }
  73. }
  74. // formatter: '{c}'
  75. }
  76. },
  77. labelLine: {
  78. show: false
  79. },
  80. hoverOffset: 0, // 设置鼠标悬停时不放大
  81. data: [
  82. { value: 10, name: '进行中', itemStyle: { normal: { color: '#3673e8' } } },
  83. { value: 8, name: '未发布', itemStyle: { normal: { color: '#61b8ff' } } },
  84. { value: 6, name: '已完成', itemStyle: { normal: { color: '#96d8a8' } } },
  85. { value: 7, name: '逾期', itemStyle: { normal: { color: '#f5b763' } } },
  86. ]
  87. }
  88. ]
  89. },
  90. };
  91. },
  92. methods: {
  93. setChart(array) {
  94. // 雷达图显示的标签
  95. let newPromise = new Promise((resolve) => {
  96. resolve();
  97. });
  98. //然后异步执行echarts的初始化函数
  99. newPromise.then(() => {
  100. const chartObj = this.$echarts.init(
  101. this.$el.querySelector("#charts_canvas")
  102. );
  103. // this.option.series[0].data = array;
  104. let _this = this
  105. _this.option.series[0].label.emphasis = _this.option.series[0].label.formatter = function (params) {
  106. console.log(params);
  107. var sum = 0;
  108. for (var i = 0; i < _this.option.series[0].data.length; i++) {
  109. sum += _this.option.series[0].data[i].value;
  110. }
  111. return '{a|' + sum + '}\n{b|表单总数}';
  112. }
  113. // 初始化雷达图
  114. _this.chartObj = chartObj;
  115. _this.chartObj.setOption(_this.option);
  116. });
  117. },
  118. setJson(array) {
  119. this.ooption = {
  120. xdata: [],
  121. sdata: [],
  122. max: 0
  123. }
  124. if (!this.chartObj) {
  125. this.setChart(array);
  126. } else {
  127. this.option.series[0].data = array;
  128. this.chartObj.setOption(this.option);
  129. }
  130. }
  131. },
  132. watch: {
  133. loginArray: {
  134. immediate: true,
  135. deep: true,
  136. handler(newValue, oldValue) {
  137. this.setJson(newValue)
  138. this.$forceUpdate();
  139. },
  140. },
  141. },
  142. mounted() {
  143. this.setJson(this.loginArray)
  144. var _this = this;
  145. window.addEventListener("resize", () => {
  146. if (_this.chartObj) {
  147. _this.chartObj.resize();
  148. }
  149. });
  150. },
  151. };
  152. </script>
  153. <style scoped>
  154. .data_body {
  155. height: 100%;
  156. /* display: flex; */
  157. position: relative;
  158. border-radius: 5px;
  159. /* border: 1px solid #eee; */
  160. margin: 0 auto;
  161. box-sizing: border-box;
  162. padding: 0;
  163. width: 100%;
  164. /* background: #fff; */
  165. }
  166. </style>