Newer
Older
dcms_front / src / views / deptAccess / deptAccessChart.vue
zhangyingjie on 12 Mar 2021 3 KB 职能单位评价样式修改
<template>
  <div class="chart-container">
    <el-radio-group v-model="radio" class="radio-group" @change="initChart">
      <el-radio v-for="radio in radioList" :key="radio.value" :label="radio.value">{{ radio.text }}</el-radio>
    </el-radio-group>
    <div ref="chart" class="chart-body" />
  </div>
</template>

<script>
import _ from 'lodash'
import echarts from 'echarts'
export default {
  name: 'DeptAccessChart',
  props: {
    list: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      radio: 'score',
      radioList: [
        {
          text: '总应处置数',
          value: 'totalCheckNum'
        },
        {
          text: '本期应处置数',
          value: 'currentCheckNum'
        },
        {
          text: '返工数',
          value: 'redoNum'
        },
        {
          text: '综合指标',
          value: 'score'
        }
      ],
      chart: null,
      x: [],
      y: []
    }
  },
  watch: {
    list() {
      this.initChart()
    }
  },
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      console.log('init chart', this.list)
      // 取x,y
      this.x = []
      this.y = []
      this.list.forEach(item => {
        this.x.push(item.departName)
        switch (this.radio) {
          case 'totalCheckNum': {
            this.y.push(item.totalCheckNum)
            break
          }
          case 'currentCheckNum': {
            this.y.push(item.currentCheckNum)
            break
          }
          case 'redoNum': {
            this.y.push(item.redoNum)
            break
          }
          case 'score': {
            this.y.push(item.score)
            break
          }
          default: break
        }
      })
      // tooltip
      const tooltip = _.find(this.radioList, ['value', this.radio]).text

      this.chart = echarts.init(this.$refs.chart)
      this.chart.setOption({
        tooltip: {
          show: true,
          trigger: 'item',
          formatter: (params) => tooltip + '<br/><span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' +
                                  params.color + '"></span>' + params.name + ':' + params.data
        },
        // toolbox: {
        //   show: true,
        //   right: '20',
        //   feature: {
        //     saveAsImage: {
        //       show: true
        //     }
        //   }
        // },
        color: '#278df9',
        xAxis: {
          data: this.x,
          axisLabel: {
            fontSize: 14
          }
        },
        yAxis: {
          axisLabel: {
            fontSize: 14
          },
          minInterval: 1
        },
        series: [{
          name: '职能单位评价',
          type: 'bar',
          data: this.y,
          barWidth: '40%',
          barMaxWidth: '100',
          tooltip: {
            position: 'right'
          }
        }]
      })
      this.chart.resize()
    }
  }
}
</script>

<style scoped>
.chart-container{
  text-align: center;
}
.radio-group{
  margin-top: 20px;
}
.chart-body{
  height: 50vh;
  width: 80%;
  margin-right: auto;
  margin-left: auto;
}
</style>