index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. xdata: [],
  19. type: [],
  20. },
  21. option: {
  22. tooltip: {
  23. trigger: "item",
  24. },
  25. xAxis: {
  26. type: "category",
  27. data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  28. },
  29. yAxis: {
  30. type: "value",
  31. },
  32. series: [
  33. {
  34. data: [120, 200, 150, 80, 70, 110, 130],
  35. type: "bar",
  36. },
  37. ],
  38. },
  39. };
  40. },
  41. methods: {
  42. setChart() {
  43. // 雷达图显示的标签
  44. let newPromise = new Promise((resolve) => {
  45. resolve();
  46. });
  47. //然后异步执行echarts的初始化函数
  48. newPromise.then(() => {
  49. const chartObj = this.$echarts.init(
  50. this.$el.querySelector("#charts_canvas")
  51. );
  52. // 初始化雷达图
  53. this.chartObj = chartObj;
  54. this.chartObj.setOption(this.option);
  55. });
  56. },
  57. },
  58. watch: {},
  59. mounted() {
  60. this.setChart();
  61. var _this = this;
  62. window.addEventListener("resize", () => {
  63. if (_this.chartObj) {
  64. _this.chartObj.resize();
  65. }
  66. });
  67. },
  68. };
  69. </script>
  70. <style scoped>
  71. .data_body {
  72. height: 100%;
  73. /* display: flex; */
  74. position: relative;
  75. border-radius: 5px;
  76. /* border: 1px solid #eee; */
  77. margin: 0 auto;
  78. box-sizing: border-box;
  79. padding: 0;
  80. width: 95%;
  81. background: #fff;
  82. }
  83. </style>