Newer
Older
smartKitchenFront / src / views / dashboard / components / layoutStackAreaChart.vue
<template>
  <!-- 近一月设备数量统计 -->
  <div class="chart-container">
    <div class="chart-header">
      <!--标题  -->
      <span class="title">设备数量统计</span>
    </div>
    <div class="chart-content" :style="{'height':height}">
      <!-- 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: "",
    },
    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 {
  background: #edf5f8;
  border-radius: 8px;
  margin:10px;
  padding: 10px;
  .chart-header {
    font-size: 14px;
    color: #2076A1;
    font-weight: 700;
  }
}
</style>