lastMonthPerformance.vue 2.51 KB
<template>
    <div :id="idstr"></div>
</template>

<script>
// 引入基本模板
const echarts = require('echarts/lib/echarts')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')

export default {
  data () {
    return {
      dataObj: {},
      option: {},
      chart: null,
      lengendColor: ['#00E8FF', '#746ef8', '#F8E71C', '#7ED321', '#FF663B'],
      clickNum: [1, 1, 1, 1, 1]
    }
  },
  props: ['message', 'idstr', 'performActive'],
  mounted () {
    console.log(this.performActive)

    this.drawLine()
  },
  methods: {
    drawLine () {
      const vm = this
      // 基于准备好的dom,初始化echarts实例
      vm.chart = echarts.init(document.getElementById(vm.idstr))
      // 清空图表
      vm.chart.clear()
      vm.option = {
        xAxis: [
          {
            type: 'category',
            data: ['客户营销', '解决方案', '智能制造', '生态合作', 'IT服务'],
            axisPointer: {
              type: 'shadow'
            },
            axisLine: {
              lineStyle: {
                color: '#FFF'
              }
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: vm.performActive === 1 ? '分数' : '部门',
            min: 0,
            max: 250,
            interval: 50,
            axisLine: {
              lineStyle: {
                color: '#FFF'
              }
            }
          }
        ],
        grid: {
          top: '20%',
          left: '10%',
          right: '10%',
          bottom: '5%',
          width: '80%', // 图例宽度
          height: '70%' // 图例高度
        },
        series: [
          {
            type: 'bar',
            barWidth: '50%',
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                { offset: 0, color: '#30DDF4' },
                { offset: 1, color: '#001873' }
              ])
            },
            data: [23.2, 76.7, 135.6, 162.2, 32.6]
          }
        ]
      }
      vm.drawBar()
    },
    drawBar () {
      // 绘制图表
      const vm = this
      vm.chart.setOption(vm.option)
      vm.eventList()
    },
    eventList () {
      const vm = this
      vm.chart.on('click', function (params) {
      })
    }
  },
  watch: {
    performActive: function (val) {
      console.log(val)
      const vm = this
      setTimeout(function () {
        vm.drawLine()
      }, 10)
    }
  }
}
</script>

<style lang="less">

</style>