linechart.vue 2.56 KB
<template>
  <div>
    <div id="channel-main" class="chart-line" v-show="lineStatus"></div>
    <div class="chart-line-empty" v-show="!lineStatus">
      <img src="@/assets/img/empty.png" />
      <div class="chart-empty-d">暂无数据</div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'linechart',

  data() {
    return {
      lineStatus: true
    }
  },

  methods: {
    getChart(lineData) {
      let entMicroCount = lineData.map(item => {
        return item.entMicroCount
      })
      let notAddEntMicroCount = lineData.map(item => {
        return item.notAddEntMicroCount
      })
      const lengthC = entMicroCount.length - 1
      if (notAddEntMicroCount.every(item => item == 0) && entMicroCount.every(item => item == 0)) {
        this.lineStatus = false
        return
      }
      this.lineStatus = true
      let dateTime = lineData.map(item => {
        return item.dayTime
      })
      let chartDom = document.getElementById('channel-main')
      let myChart = echarts.init(chartDom)
      let option

      option = {
        legend: {
          left: 'auto',
          icon: 'stack',
          itemHeight: 2,
          textStyle: { color: ['#5850FF', '#FF6D00'] },
          itemWidth: 12
        },
        tooltip: {
          trigger: 'axis'
        },
        color: ['#5850FF', '#FF6D00'],
        grid: {
          left: '3%',
          right: '4%',
          bottom: '15%',
          containLabel: true
        },
        dataZoom: [
          {
            startValue: lengthC - 29,
            endValue: lengthC
          },
          {
            type: 'inside',
            startValue: lengthC - 29,
            endValue: lengthC
          }
        ],
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: dateTime
        },
        yAxis: {
          type: 'value',
          minInterval: 1
        },
        series: [
          {
            name: '未加企微客户数',
            type: 'line',
            lineStyle: { color: '#5850FF' },
            data: notAddEntMicroCount
          },
          {
            name: '企微客户数',
            type: 'line',
            lineStyle: { color: '#FF6D00' },
            data: entMicroCount
          }
        ]
      }

      option && myChart.setOption(option)
    }
  }
}
</script>

<style scoped lang="scss">
.chart-line {
  height: 300px;
}
.chart-line-empty {
  height: 300px;
  text-align: center;
  color: #666;
  img {
    margin-top: 100px;
    width: 64px;
    height: 32px;
    margin-bottom: 12px;
  }
}
</style>