index.vue 2.0 KB

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