<template> <div class="chart-container"> <div ref="chart" class="chart"></div> </div> </template> <script> import echarts from 'echarts'; export default { data() { return { chartData: [], // 存储统计数据 }; }, mounted() { // 在组件挂载之后初始化图表 this.initChart(); }, methods: { initChart() { const chart = echarts.init(this.$refs.chart); const option = { title: { text: '销售额变化趋势', }, xAxis: { type: 'category', data: this.chartData.map(item => item.time), }, yAxis: { type: 'value', }, series: [{ type: 'line', data: this.chartData.map(item => item.amount), }], }; chart.setOption(option); }, }, }; </script>