Newer
Older
smartKitchenFront / src / views / dashboard / components / layoutChartRadar.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内容 -->
      <baseRadarChartVue :seriesData="seriesData" :indicator="indicator" />
    </div>
  </div>
</template>

<script>
import baseRadarChartVue from "../../../components/echart/radarChart/baseRadarChart.vue";
import { getUserCount } from "@/api/cockpit/cockpit";
export default {
  name: "layoutChartSelect",
  components: {
    baseRadarChartVue,
  },
  props: {
    name: {
      type: String,
      default: "",
    },
    width: {
      type: String,
      default: "500px",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      seriesData: [],
      indicator: [],
      legend: [],
    };
  },
  mounted() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      getUserCount().then((res) => {
        // {roleName: '集团用户', userCount: 5}
        let data = [];
        let legend = [];
        for (var i = 0; i < res.data.length; i++) {
          data.push(res.data[i].userCount);
          legend.push(res.data[i].roleName);
        }
        this.seriesData = [
          {
            type: "radar",
            data: [
              {
                value: data,
                name: "注册用户数",
              },
            ],
          },
        ];
        // this.legend = legend
        let max = 0;
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].userCount > max){
            max = res.data[i].userCount
          }
        }
        this.indicator = res.data.map((item) => {
          return {
            name: item.roleName,
            max: max,
          };
        });
      });
    },
  },
};
</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;
  }
  .chart-content {
    // width: 600px;
    // height: 400px;
  }
}
</style>