randar1.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. fontSize: 12
  35. },
  36. radius: ['0%', '70%'],
  37. center: ['50%', '55%'],
  38. nameGap: 5,
  39. },
  40. series: [
  41. {
  42. name: '综合平均分',
  43. type: 'radar',
  44. data: [
  45. {
  46. value: [86, 76, 35, 85, 80, 86],
  47. itemStyle: {
  48. color: '#3673E8' // 设置数据点的颜色
  49. },
  50. lineStyle: {
  51. normal: {
  52. color: '#3673E8' //
  53. }
  54. },
  55. areaStyle: {
  56. normal: {
  57. color: '#3673E833' //
  58. }
  59. }
  60. }
  61. ]
  62. }
  63. ]
  64. },
  65. };
  66. },
  67. methods: {
  68. setChart(array) {
  69. // 雷达图显示的标签
  70. let newPromise = new Promise((resolve) => {
  71. resolve();
  72. });
  73. //然后异步执行echarts的初始化函数
  74. newPromise.then(() => {
  75. const chartObj = this.$echarts.init(
  76. this.$el.querySelector("#charts_canvas")
  77. );
  78. // this.option.series[0].data = array;
  79. // 初始化雷达图
  80. this.chartObj = chartObj;
  81. this.chartObj.setOption(this.option);
  82. });
  83. },
  84. setJson(array) {
  85. this.ooption = {
  86. xdata: [],
  87. sdata: [],
  88. max: 0
  89. }
  90. if (!this.chartObj) {
  91. this.setChart(array);
  92. } else {
  93. this.option.series[0].data = array;
  94. this.chartObj.setOption(this.option);
  95. }
  96. }
  97. },
  98. watch: {
  99. loginArray: {
  100. immediate: true,
  101. deep: true,
  102. handler(newValue, oldValue) {
  103. this.setJson(newValue)
  104. this.$forceUpdate();
  105. },
  106. },
  107. },
  108. mounted() {
  109. this.setJson(this.loginArray)
  110. var _this = this;
  111. window.addEventListener("resize", () => {
  112. if (_this.chartObj) {
  113. _this.chartObj.resize();
  114. }
  115. });
  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: 100%;
  130. /* background: #fff; */
  131. }
  132. </style>