Overview.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div>
  3. <div style="display:flex">
  4. <div style="width: 600px">
  5. <Editor
  6. :code="toString(dataformParams)"
  7. height="650px"
  8. :showDefaultTips="false"
  9. @change="setXhrParam"
  10. />
  11. </div>
  12. <div style="padding: 20px">
  13. <div style="border: 1px solid #d6d6d6; margin-bottom: 10px">
  14. <div id="echarts_test" style="width: 800px;height:500px"></div>
  15. </div>
  16. <el-button type="primary" @click="ceshisss">刷新</el-button>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import Editor from "./editorCode/index.vue";
  23. export default {
  24. components: {
  25. Editor
  26. },
  27. data() {
  28. return {
  29. dataformParams: {},
  30. getData: ''
  31. }
  32. },
  33. mounted() {
  34. this.$nextTick(() =>{
  35. this.getEcharts()
  36. })
  37. },
  38. methods: {
  39. setXhrParam(value) {
  40. this.getData = value
  41. },
  42. ceshisss() {
  43. console.log(this.dataformParams)
  44. this.getData = eval("(" + this.getData + ")")
  45. this.getEcharts(this.getData)
  46. },
  47. // 数组转字符串
  48. toString(obj = {}) {
  49. return String(JSON.stringify(obj, null, 2));
  50. },
  51. getEcharts(val) {
  52. let option = {}
  53. if (!val) {
  54. option = {
  55. tooltip: {
  56. trigger: 'axis'
  57. },
  58. legend: {
  59. data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
  60. },
  61. grid: {
  62. left: '3%',
  63. right: '4%',
  64. bottom: '3%',
  65. containLabel: true
  66. },
  67. xAxis: {
  68. type: 'category',
  69. boundaryGap: false,
  70. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  71. },
  72. yAxis: {
  73. type: 'value'
  74. },
  75. series: [
  76. {
  77. name: 'Email',
  78. type: 'line',
  79. stack: 'Total',
  80. data: [120, 132, 101, 134, 90, 230, 210]
  81. },
  82. {
  83. name: 'Union Ads',
  84. type: 'line',
  85. stack: 'Total',
  86. data: [220, 182, 191, 234, 290, 330, 310]
  87. },
  88. {
  89. name: 'Video Ads',
  90. type: 'line',
  91. stack: 'Total',
  92. data: [150, 232, 201, 154, 190, 330, 410]
  93. },
  94. {
  95. name: 'Direct',
  96. type: 'line',
  97. stack: 'Total',
  98. data: [320, 332, 301, 334, 390, 330, 320]
  99. },
  100. {
  101. name: 'Search Engine',
  102. type: 'line',
  103. stack: 'Total',
  104. data: [820, 932, 901, 934, 1290, 1330, 1320]
  105. }
  106. ]
  107. };
  108. } else {
  109. option = val
  110. }
  111. let dom = document.getElementById('echarts_test');
  112. dom.removeAttribute("_echarts_instance_")
  113. let myChart = this.$echarts.init(dom);
  114. myChart.setOption(option);
  115. window.addEventListener("resize", function () {
  116. myChart.resize()
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. </style>