From 3671ce3c0c741b443c6a2e04321344a675c71d11 Mon Sep 17 00:00:00 2001 From: cuiyouliang <799699717@qq.com> Date: Mon, 30 Jun 2025 17:36:41 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81echarts=E9=85=8D=E7=BD=AE=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/dashboard/LineChartnew.vue | 66 ++++++++++++++-------------- src/views/index.vue | 1 - 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/views/dashboard/LineChartnew.vue b/src/views/dashboard/LineChartnew.vue index 24901fe..3573691 100644 --- a/src/views/dashboard/LineChartnew.vue +++ b/src/views/dashboard/LineChartnew.vue @@ -28,36 +28,38 @@ export default { required: true } }, - defaultOption: { - title: { - text: null, - left: 'center' - }, - tooltip: { - show: true, - trigger: 'axis' - }, - legend: { - data: [] - }, - grid: { - left: '3%', - right: '4%', - bottom: '3%', - containLabel: true - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: [] - }, - yAxis: { - type: 'value' - }, - series: [] - }, + data() { - return {}; + return { + defaultOption: { + title: { + text: null, + left: 'center' + }, + tooltip: { + show: true, + trigger: 'axis' + }, + legend: { + data: [] + }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: [] + }, + yAxis: { + type: 'value' + }, + series: [] + } + }; }, mounted() { this.initChart(); @@ -65,12 +67,10 @@ export default { methods: { initChart() { console.log(this.chartData); - Object.keys(this.chartData).forEach((key) => { - this.defaultOption[key] = this.chartData[key]; - }); + this.defaultOption = { ...this.defaultOption, ...this.chartData }; const chartDom = document.getElementById('LineChartnew'); const myChart = echarts.init(chartDom); - myChart(this.defaultOption); + myChart.setOption(this.defaultOption); } /* setOptions(chartData) { diff --git a/src/views/index.vue b/src/views/index.vue index 10028b6..913f374 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -92,7 +92,6 @@ const LinechartData = ref({ boundaryGap: false, data: [] }, - legend: {}, series: [ { name: '用户量', data: [] }, { name: '在线用户', data: [] },