Newer
Older
smartKitchenFront / src / views / dashboard / components / layoutStackAreaChartTrend.vue
<template>
  <!-- 用户数量变化趋势 -->
  <div class="chart-container" :style="{ 'height': height, 'width': width }">
    <div class="chart-header">
      <!--标题  -->
      <span class="title">用户数量变化趋势</span>
    </div>
    <div class="chart-content" :style="{ 'height': parseInt(height) - 40 + 'px'}">
      <!-- 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: {
    async fetchData() {
      // 获取近一月设备数量统计数据
      let res = await getUserTrend()
      const { data } = res
        // 图表数据
        let seriesData = [];
        let legend = []
        if (data.length > 0) {
          for(var user in data[0]){
            legend.push(user)
            seriesData.push({
              name:user,
              data:[]
            })
          }
        }
        for (var i =0; i<data.length;i++) {
          seriesData.forEach(item => {
            if (item.name in data[i]) {
              item.data.push(data[i][item.name])
            }
          })
        }
        this.seriesData = seriesData.slice(1)
        // x轴数据
        let xData = seriesData.slice(0,1)[0]
        this.xAxisData = xData.data;
        // 提示
        this.legend = legend.slice(1)
    },
  },
};
</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>