Newer
Older
smartKitchenFront / src / views / dashboard / components / layoutChartDoughnu.vue
<template>
  <!-- 设备品类统计 -->
  <div class="chart-container">
    <div class="chart-header">
      <!--标题  -->
      <span class="title"></span>
    </div>
    <div class="chart-content" :style="{'height':height,'width':width}">
      <!-- echarts内容 -->
      <doughnutChart :seriesData="seriesData" :title="title" />
    </div>
  </div>
</template>

<script>
import doughnutChart from '../../../components/echart/pieChart/doughnutChart.vue';
import { getDeviceCategory } from '@/api/cockpit/cockpit'
export default {
  name: "layoutChartSelect",
  components: {
    doughnutChart,
  },
  props: {
    name: {
      type: String,
      default: "",
    },
    width:{
      type: String,
      default: "500px"
    },
    height:{
      type: String,
      default: "250px"
    }
  },
  data() {
    return {
      seriesData: [],
      title:''
    };
  },
  mounted() {
    this.fetchData()
  },
  methods:{
    fetchData() {
      getDeviceCategory().then(res => {
        let arr = []
        this.seriesData = res.data.map(item => {
          arr.push(item.deviceCount)
          return{
            name:item.categoryName,
            value:item.deviceCount
          }
        })
        this.title = `总\n\n${arr.reduce((pre,cur) => pre + cur)}`
      })
    }
  }
};
</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>