Newer
Older
GDT_FRONT / src / views / popup / components / staffLine.vue
wangxitong on 9 Feb 2023 4 KB 0209
<template>
  <div id="staff-line" class="container">
    <ve-line
      v-if="isShow"
      :width='width'
      :height='height'
      :judge-width="true"
      :data="chartData"
      :extend="extend"
      :settings="chartSettings"/>
  </div>
</template>

<script>

export default {
  name: 'StaffLine',
  data() {
    return {
      isShow: true,
      height: '0',
      width: '0',
      chartSettings: {
        labelMap: { time: '时间' },
        metrics: [],
        dimension: ['time']
      },
      extend: {
        color: ['#0071ff88', '#00afff88', '#00fdc088'],
        legend: {
          textStyle: {
            color: '#cce9ff',
            fontWeight: 'bold'
          },
          lineStyle: {
            width: 10
          },
          data: ['一期主楼', '二期主楼', '录制楼']
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#cce9ff'
            }
          }
        },
        grid: {
          left: '1%',
          right: '2%',
          bottom: '0%',
          top: '20%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisLabel: {
            color: '#cce9ff'
          }
        },
        yAxis: {
          position: 'left',
          type: 'value',
          axisLabel: {
            color: '#cce9ff'
          }
        },
        series: {
          type: 'line',
          symbol: 'circle',
          symbolSize: 6,
          areaStyle: {},
          emphasis: {
            focus: 'series'
          }
        }
      },
      chartData: {
        columns: [],
        rows: []
      }
    }
  },
  mounted() {
    this.height = document.getElementById('staff-line').clientHeight - 10 + 'px'
    this.width = document.getElementById('staff-line').clientWidth - 10 + 'px'
    const that = this
    window.addEventListener('resize', function() {
      that.reload()
    })
    this.fetchData()
  },
  methods: {
    async reload() {
      this.isShow = false
      await this.$nextTick()
      this.height = document.getElementById('staff-line').clientHeight - 10 + 'px'
      this.width = document.getElementById('staff-line').clientWidth - 10 + 'px'
      this.isShow = true
    },
    // 获取数据
    fetchData() {
      this.chartData.columns = ['time', '一期主楼', '二期主楼', '录制楼']
      this.chartSettings.metrics = ['一期主楼', '二期主楼', '录制楼']
      this.chartSettings.labelMap = { 'time': '时间' }
      // 模拟数据
      this.chartData.rows = [
        { time: '0', '一期主楼': '1345', '二期主楼': '942', '录制楼': '194'},
        { time: '1', '一期主楼': '1445', '二期主楼': '1012', '录制楼': '294'},
        { time: '2', '一期主楼': '1545', '二期主楼': '1192', '录制楼': '394'},
        { time: '3', '一期主楼': '1645', '二期主楼': '1142', '录制楼': '494'},
        { time: '4', '一期主楼': '1745', '二期主楼': '1072', '录制楼': '594'},
        { time: '5', '一期主楼': '1645', '二期主楼': '912', '录制楼': '494'},
        { time: '6', '一期主楼': '1665', '二期主楼': '992', '录制楼': '294'},
        { time: '7', '一期主楼': '1635', '二期主楼': '942', '录制楼': '494'},
        { time: '8', '一期主楼': '1595', '二期主楼': '922', '录制楼': '394'},
        { time: '9', '一期主楼': '1545', '二期主楼': '942', '录制楼': '394'},
        { time: '10', '一期主楼': '1445', '二期主楼': '900', '录制楼': '234'},
        { time: '11', '一期主楼': '1345', '二期主楼': '1000', '录制楼': '294'},
        { time: '12', '一期主楼': '1375', '二期主楼': '800', '录制楼': '394'},
        { time: '13', '一期主楼': '1325', '二期主楼': '842', '录制楼': '244'},
        { time: '14', '一期主楼': '1345', '二期主楼': '742', '录制楼': '194'},
        { time: '15', '一期主楼': '1445', '二期主楼': '642', '录制楼': '184'},
        { time: '16', '一期主楼': '1345', '二期主楼': '542', '录制楼': '174'},
        { time: '17', '一期主楼': '1545', '二期主楼': '442', '录制楼': '224'},
        { time: '18', '一期主楼': '1345', '二期主楼': '542', '录制楼': '194'},
        { time: '19', '一期主楼': '1245', '二期主楼': '642', '录制楼': '184'},
        { time: '20', '一期主楼': '1215', '二期主楼': '542', '录制楼': '194'},
        { time: '21', '一期主楼': '1235', '二期主楼': '442', '录制楼': '164'},
        { time: '22', '一期主楼': '1195', '二期主楼': '342', '录制楼': '144'},
        { time: '23', '一期主楼': '1145', '二期主楼': '242', '录制楼': '114'}
      ]
    }
  }
}
</script>
<style lang="scss" scoped>
  .container{
    position:relative;
    width: 100%;
    height:100%;
  }
</style>