<template>
  <div>
    <div id="main" :style="{width: '400px', height: '400px'}"></div>
  </div>
</template>

<script>
import portal from '@/api/portal.js'
import * as echarts from 'echarts'
export default {
  data() {
    return {
      restPPT:0,
    }
  },
  mounted() {
    this.getDisk()
    this.getDashboard()
  },
  methods: {
    getDisk() {
      portal.getHD().then((res) => {
        this.restPPT=res[0].restPPT
        this.getDashboard()
      })
    },
    getDashboard() {
      var chartDom = document.getElementById('main')
      var myChart = echarts.init(chartDom)
      var option
      option = {
        series: [
          {
            type: 'gauge',
            progress: {
              show: true,
              width: 18,
            },
            axisLine: {
              lineStyle: {
                width: 18,
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              length: 15,
              lineStyle: {
                width: 2,
                color: '#999',
              },
            },
            axisLabel: {
              distance: 25,
              color: '#999',
              fontSize: 20,
            },
            anchor: {
              show: true,
              showAbove: true,
              size: 25,
              itemStyle: {
                borderWidth: 10,
              },
            },
            title: {
              show: false,
            },
            detail: {
              valueAnimation: true,
              fontSize: 50,
              offsetCenter: [0, '70%'],
            },
            data: [
              {
                value: this.restPPT,
              },
            ],
          },
        ],
      }

      option && myChart.setOption(option)
      //防止越界，重绘canvas
      window.onresize = myChart.resize
      myChart.setOption(option) //设置option
    },
  },
}
</script>

<style lang="scss" scoped>
</style>