sunburst.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="data_body">
  3. <div class="noMind" v-if="mindV">
  4. <img src="../../assets/nominddata.png" alt />
  5. </div>
  6. <!-- <img src="../../assets/dataimage/1.png" style="width:90%" /> -->
  7. <div
  8. id="charts_canvas"
  9. class="echart"
  10. style="width: 100%; height: 100%"
  11. ></div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: ["Josn", "num"],
  17. data() {
  18. return {
  19. mindV: true,
  20. chartObj: null,
  21. timer: null,
  22. ooption: [],
  23. option: {
  24. series: {
  25. type: "sunburst",
  26. data: [],
  27. radius: [30, "90%"],
  28. label: {
  29. rotate: "radial",
  30. },
  31. },
  32. },
  33. };
  34. },
  35. methods: {
  36. setChart(option) {
  37. // 雷达图显示的标签
  38. let newPromise = new Promise((resolve) => {
  39. resolve();
  40. });
  41. //然后异步执行echarts的初始化函数
  42. newPromise.then(() => {
  43. const chartObj = this.$echarts.init(
  44. //劳动课程
  45. this.$el.querySelector("#charts_canvas")
  46. );
  47. this.option.series.data = option;
  48. // 初始化雷达图
  49. this.chartObj = chartObj;
  50. this.chartObj.setOption(this.option);
  51. });
  52. },
  53. setData() {
  54. if (!Object.keys(this.Josn).length) {
  55. this.mindV = true;
  56. } else {
  57. this.mindV = false;
  58. }
  59. var res = this.Josn;
  60. var _array = [];
  61. let i = 0;
  62. for (var item in res) {
  63. let num = Object.keys(res);
  64. let count = 10 / num.length;
  65. let _item = res[item];
  66. _array.push({ name: _item.name, value: count, children: [] });
  67. let j = 0;
  68. for (var item2 in _item.child) {
  69. let num2 = Object.keys(res);
  70. let count2 = count / num2.length;
  71. let _item2 = _item.child[item2];
  72. _array[i].children.push({
  73. name: _item2.name,
  74. value: count2,
  75. children: [],
  76. });
  77. for (var item3 in _item2.child) {
  78. let num3 = Object.keys(res);
  79. let count3 = count2 / num3.length;
  80. let _item3 = _item2.child[item3];
  81. _array[i].children[j].children.push({
  82. name: _item3.name,
  83. value: count3,
  84. });
  85. }
  86. j++;
  87. }
  88. i++;
  89. console.log(item);
  90. }
  91. this.ooption = _array;
  92. if (!this.chartObj) {
  93. this.setChart(this.ooption);
  94. } else {
  95. this.option.series.data = this.ooption;
  96. this.chartObj.setOption(this.option);
  97. }
  98. },
  99. },
  100. watch: {
  101. num: {
  102. handler: function (newVal, oldVal) {
  103. this.setData();
  104. },
  105. deep: true,
  106. },
  107. Josn: {
  108. handler: function (newVal, oldVal) {},
  109. deep: true,
  110. },
  111. },
  112. mounted() {
  113. this.setData();
  114. var _this = this;
  115. // _this.timer = setInterval(() => {
  116. // if (_this.chartObj) {
  117. // _this.chartObj.resize();
  118. // }
  119. // }, 0);
  120. // window.addEventListener("resize", () => {
  121. // if (_this.chartObj) {
  122. // _this.chartObj.resize();
  123. // }
  124. // });
  125. },
  126. beforeDestroy() {
  127. // clearInterval(this.timer);
  128. // this.timer = null
  129. },
  130. };
  131. </script>
  132. <style scoped>
  133. .data_body {
  134. /* display: flex; */
  135. /* flex-direction: column; */
  136. width: 500px;
  137. height: 450px;
  138. /* height: 500px; */
  139. /* margin: 15px 5px 0 0; */
  140. background: #fff;
  141. overflow: hidden;
  142. flex-shrink: 0;
  143. position: relative;
  144. }
  145. .noMind {
  146. position: absolute;
  147. display: flex;
  148. justify-content: center;
  149. align-items: center;
  150. width: 100%;
  151. height: 100%;
  152. z-index: 999;
  153. background: #fff;
  154. }
  155. </style>