index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. data() {
  11. return {
  12. chartObj: null,
  13. ooption: {
  14. xdata: [],
  15. sdata: [],
  16. },
  17. option: {
  18. tooltip: {},
  19. radar: {
  20. // shape: 'circle',
  21. indicator: [
  22. { name: '目标一', max: 10 },
  23. { name: '目标二', max: 10 },
  24. { name: '目标三', max: 10 },
  25. { name: '目标四', max: 10 },
  26. { name: '目标五', max: 10 }
  27. ]
  28. },
  29. series: [
  30. {
  31. areaStyle: {},
  32. name: '学生综合评价',
  33. type: 'radar',
  34. data: [
  35. {
  36. value: [5, 7, 7, 8, 5, 6],
  37. name: ''
  38. }
  39. ]
  40. }
  41. ]
  42. },
  43. };
  44. },
  45. methods: {
  46. setChart(option) {
  47. // 雷达图显示的标签
  48. let newPromise = new Promise((resolve) => {
  49. resolve();
  50. });
  51. //然后异步执行echarts的初始化函数
  52. newPromise.then(() => {
  53. const chartObj = this.$echarts.init(
  54. //劳动课程
  55. this.$el.querySelector("#charts_canvas")
  56. );
  57. // this.option.xAxis.data = option.xdata;
  58. // this.option.series[0].data = option.sdata;
  59. // 初始化雷达图
  60. this.chartObj = chartObj;
  61. this.chartObj.setOption(this.option);
  62. });
  63. },
  64. },
  65. watch: {
  66. },
  67. mounted() {
  68. this.setChart(this.ooption);
  69. var _this = this;
  70. window.addEventListener("resize", () => {
  71. if (_this.chartObj) {
  72. _this.chartObj.resize();
  73. }
  74. });
  75. },
  76. };
  77. </script>
  78. <style scoped>
  79. .data_body {
  80. height: 100%;
  81. /* display: flex; */
  82. position: relative;
  83. border-radius: 5px;
  84. /* border: 1px solid #eee; */
  85. margin: 0 auto;
  86. box-sizing: border-box;
  87. padding: 0;
  88. width: 95%;
  89. background: #fff;
  90. }
  91. </style>