Newer
Older
GDT_FRONT / src / views / popup / components / powerLine1.vue
wangxitong on 9 Feb 2023 2 KB 0209
<template>
  <div id="power-line" class="container">
    <ve-bar
      :style='{"height": height,"width": width}'
      :width='width'
      :height='height'
      :judge-width="true"
      :data="chartData"
      :extend="extend"
      :settings="chartSettings"/>
  </div>
</template>

<script>

import * as echarts from 'echarts';
import { multiScorePatrol } from '@/api/pop'
export default {
  name: 'PowerLine',
  data() {
    return {
      title: {
        text: '巡视安防评分',
        textStyle: {
          color: '#cce9ff',
          fontSize: 15
        },
        padding: [5, 0, 0, 120]
      },
      height: '0',
      width: '0',
      chartSettings: {
        labelMap: { name: '日期' },
        metrics: [],
        dimension: ['date']
      },
      extend: {
        grid: {
          bottom: '0%',
          top: '12%',
          containLabel: true
        },
        yAxis: {
          axisLabel: {
            color: '#cce9ff'
          }
        },
        xAxis: {
          axisLabel: {
            color: '#cce9ff'
          }
        },
        legend: {
          top: '0px',
          data: ['巡视安防评分'],
          textStyle: {
            color: '#cce9ff',
            fontWeight: 'bold'
          }
        },
        series: {
          color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [{ offset: 0, color: '#38a0d6cc' }, { offset: 1, color: '#74e3b3cc' }], false),
          type: 'bar',
          symbol: 'circle',
          symbolSize: 8,
          stack: 'Total',
          label: {
            show: true,
            position: 'insideRight'
          },
          areaStyle: {},
          emphasis: {
            focus: 'series'
          }
        },
        tooltip: {
          trigger: 'axis',
          position: function(pt) {
            return [pt[0], '10']
          }
        }
      },
      chartData: {
        columns: [],
        rows: []
      }
    }
  },
  mounted() {
    this.height = document.getElementById('power-line').clientHeight - 10 + 'px'
    this.width = document.getElementById('power-line').clientWidth - 10 + 'px'
    this.fetchData()
  },
  methods: {
    // 获取数据
    fetchData() {
      this.chartData.columns = ['date', 'score']
      this.chartSettings.metrics = ['score']
      this.chartSettings.labelMap = { 'date': '日期', 'score': '巡视安防评分' }
      multiScorePatrol().then(response => {
        if (response.code === 200) {
          this.chartData.rows = response.data
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.container{
  position:relative;
  width: 100%;
  height:100%;
}
</style>