index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="data_body">
  3. <div style="width: 100%; height: 100%">
  4. <div
  5. id="charts_canvas"
  6. class="echart"
  7. style="width: 100%; height: 100%"
  8. ></div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. pusaDep: {
  16. type: Array,
  17. },
  18. },
  19. data() {
  20. return {
  21. chartObj: null,
  22. option: {
  23. tooltip: {
  24. trigger: "item",
  25. formatter: "{b} : {c}%",
  26. },
  27. // legend: {
  28. // data: ["评价", "授课", "创建", "登录"],
  29. // },
  30. series: [
  31. {
  32. type: "funnel",
  33. left: "5%",
  34. top: 10,
  35. bottom: 0,
  36. width: "95%",
  37. min: 0,
  38. max: 100,
  39. minSize: "0%",
  40. maxSize: "100%",
  41. sort: "descending",
  42. label: {
  43. show: true,
  44. position: "inside",
  45. },
  46. labelLine: {
  47. length: 10,
  48. lineStyle: {
  49. width: 1,
  50. type: "solid",
  51. },
  52. },
  53. itemStyle: {
  54. borderColor: "#fff",
  55. borderWidth: 1,
  56. },
  57. data: [
  58. // { value: 20, name: "登录" },
  59. // { value: 40, name: "创建" },
  60. // { value: 60, name: "授课" },
  61. // { value: 80, name: "评价" },
  62. ],
  63. },
  64. ],
  65. },
  66. };
  67. },
  68. methods: {
  69. setChart(array) {
  70. // 雷达图显示的标签
  71. let newPromise = new Promise((resolve) => {
  72. resolve();
  73. });
  74. //然后异步执行echarts的初始化函数
  75. newPromise.then(() => {
  76. const chartObj = this.$echarts.init(
  77. this.$el.querySelector("#charts_canvas")
  78. );
  79. // 初始化雷达图
  80. this.option.series[0].data = array;
  81. this.chartObj = chartObj;
  82. this.chartObj.setOption(this.option);
  83. });
  84. },
  85. setArray(array){
  86. let _array = array;
  87. if (!this.chartObj) {
  88. this.setChart(_array);
  89. } else {
  90. this.option.series[0].data = _array;
  91. this.chartObj.setOption(this.option);
  92. }
  93. this.$forceUpdate();
  94. },
  95. },
  96. watch: {
  97. pusaDep: {
  98. immediate: true,
  99. deep: true,
  100. handler(newValue, oldValue) {
  101. this.setArray(newValue)
  102. },
  103. },
  104. },
  105. mounted() {
  106. this.setArray(this.pusaDep)
  107. var _this = this;
  108. window.addEventListener("resize", () => {
  109. if (_this.chartObj) {
  110. _this.chartObj.resize();
  111. }
  112. });
  113. },
  114. created() {
  115. this.setChart();
  116. },
  117. };
  118. </script>
  119. <style scoped>
  120. .data_body {
  121. height: 100%;
  122. /* display: flex; */
  123. position: relative;
  124. border-radius: 5px;
  125. /* border: 1px solid #eee; */
  126. margin: 0 auto;
  127. box-sizing: border-box;
  128. padding: 0;
  129. width: 95%;
  130. background: #fff;
  131. }
  132. </style>