randar2.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. radar: {
  25. indicator: [
  26. { name: '煜煜星光', max: 100 },
  27. { name: '个人写真', max: 100 },
  28. { name: '明灯导航', max: 100 },
  29. { name: '教师耕耘', max: 100 },
  30. { name: '其他', max: 100 }
  31. ],
  32. axisName: {
  33. color: '#000'
  34. },
  35. axisName: {
  36. color: '#000',
  37. fontSize: 12
  38. },
  39. radius: ['0%', '70%'],
  40. center: ['50%', '55%'],
  41. nameGap: 5,
  42. },
  43. series: [
  44. {
  45. name: '综合平均分',
  46. type: 'radar',
  47. data: [
  48. {
  49. value: [86, 76, 35, 85, 80, 86],
  50. itemStyle: {
  51. color: '#F5B763' // 设置数据点的颜色
  52. },
  53. lineStyle: {
  54. normal: {
  55. color: '#F5B763' //
  56. }
  57. },
  58. areaStyle: {
  59. normal: {
  60. color: '#F5B76333' //
  61. }
  62. }
  63. }
  64. ]
  65. }
  66. ]
  67. },
  68. };
  69. },
  70. methods: {
  71. setChart(array) {
  72. // 雷达图显示的标签
  73. let newPromise = new Promise((resolve) => {
  74. resolve();
  75. });
  76. //然后异步执行echarts的初始化函数
  77. newPromise.then(() => {
  78. const chartObj = this.$echarts.init(
  79. this.$el.querySelector("#charts_canvas")
  80. );
  81. // this.option.series[0].data = array;
  82. // 初始化雷达图
  83. this.chartObj = chartObj;
  84. this.chartObj.setOption(this.option);
  85. });
  86. },
  87. setJson(array) {
  88. this.ooption = {
  89. xdata: [],
  90. sdata: [],
  91. max: 0
  92. }
  93. if (!this.chartObj) {
  94. this.setChart(array);
  95. } else {
  96. this.option.series[0].data = array;
  97. this.chartObj.setOption(this.option);
  98. }
  99. }
  100. },
  101. watch: {
  102. loginArray: {
  103. immediate: true,
  104. deep: true,
  105. handler(newValue, oldValue) {
  106. this.setJson(newValue)
  107. this.$forceUpdate();
  108. },
  109. },
  110. },
  111. mounted() {
  112. this.setJson(this.loginArray)
  113. var _this = this;
  114. window.addEventListener("resize", () => {
  115. if (_this.chartObj) {
  116. _this.chartObj.resize();
  117. }
  118. });
  119. },
  120. };
  121. </script>
  122. <style scoped>
  123. .data_body {
  124. height: 100%;
  125. /* display: flex; */
  126. position: relative;
  127. border-radius: 5px;
  128. /* border: 1px solid #eee; */
  129. margin: 0 auto;
  130. box-sizing: border-box;
  131. padding: 0;
  132. width: 100%;
  133. /* background: #fff; */
  134. }
  135. </style>