index.vue 2.0 KB

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