<template> <!-- 用户数量变化趋势 --> <div class="chart-container"> <div class="chart-header"> <!--标题 --> <span class="title">用户数量变化趋势</span> </div> <div class="chart-content" :style="{ height: height, width: width }"> <!-- echarts内容 --> <gradientLineChart :seriesData="seriesData" :xAxisData="xAxisData" :legend="legend" /> </div> </div> </template> <script> import gradientLineChart from "../../../components/echart/lineChart/gradientLineChart.vue"; import { getUserTrend } from "@/api/cockpit/cockpit"; export default { name: "layoutChartSelectTrend", components: { gradientLineChart, }, props: { width: { type: String, default: "500px", }, height: { type: String, default: "300px", }, }, data() { return { seriesData: [], xAxisData: [], yAxisData: [], legend: [], }; }, mounted() { this.fetchData(); }, methods: { fetchData() { // 获取近一月设备数量统计数据 getUserTrend().then((res) => { // 图表数据 let seriesData = []; let legend = [] if (res.data.length > 0) { for(var user in res.data[0]){ legend.push(user) seriesData.push({ name:user, data:[] }) } } for (var i =0; i<res.data.length;i++) { seriesData.forEach(item => { if (item.name in res.data[i]) { item.data.push(res.data[i][item.name]) } }) } this.seriesData = seriesData.slice(1) // x轴数据 this.xAxisData = seriesData.slice(0,1).data; // 提示 this.legend = legend.slice(1) console.log(this.legend) }); }, }, }; </script> <style lang="scss" scoped> .chart-container { .chart-header { width: 600px; align-items: center; display: flex; justify-content: space-between; } } </style>