<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 { getDeviceStatistics } from "@/api/cockpit/cockpit"; export default { name: "layoutChartSelect", components: { gradientLineChart, }, props: { name: { type: String, default: "", }, width: { type: String, default: "500px", }, height: { type: String, default: "250px", }, }, data() { return { seriesData: [], xAxisData: [], yAxisData: [], legend: [], }; }, mounted() { this.fetchData(); }, methods: { fetchData() { // 获取近一月设备数量统计数据 getDeviceStatistics().then((res) => { // 图表数据 let activeDevice = [] let iotDevice = [] let unIotDevice = [] let total = [] for (var i = 0; i < res.data.length; i++) { activeDevice.push(res.data[i].activeDevice) iotDevice.push(res.data[i].iotDevice) unIotDevice.push(res.data[i].unIotDevice) total.push(res.data[i].total) } this.seriesData = [ { name:'设备总数', data:total }, { name:'IOT设备数量', data:iotDevice }, { name:'非IOT设备数量', data:unIotDevice }, { name:'激活设备数量', data:activeDevice } ] // x轴数据 let xAxisData = []; for (var i = 0; i < res.data.length; i++) { xAxisData.push(res.data[i].date) } this.xAxisData = xAxisData // 提示 this.legend = ["设备总数", "IOT设备数量", "非IOT设备数量", "激活设备数量"]; }); }, }, }; </script> <style lang="scss" scoped> .chart-container { .chart-header { width: 600px; align-items: center; display: flex; justify-content: space-between; } .chart-content { // width: 600px; // height: 400px; } } </style>