DoubleBarChart.vue 1.91 KB
<template>
  <div>
    <div :id="domId" style="width: 100%" :style="{ height }"></div>
  </div>
</template>

<script type="text/ecmascript-6">
import utils from '../../../utils/util'
import * as echarts from 'echarts'
import getBarLineOptions from './DoubleBarOptions'
export default {
  name: 'DoubleBarChart',
  props: {
    height: {
      type: String
    },
    domId: {
      type: String,
      default: 'bar-line'
    },
    dataList: {
      type: Array,
      default: () => []
    },
    tooltipFormatterObj: {
      type: Array,
      default: () => {
        return [
          {
            label: '数量',
            attrName: 'num'
          },
          {
            label: '环比',
            attrName: 'hrate',
            addSymbol: '%'
          },
          {
            label: '同比',
            attrName: 'trate',
            addSymbol: '%'
          }
        ]
      }
    }
  },
  data() {
    return {
      barLineOptions: [],
      moveAttr: {
        // speed: 900,
        seriesIndex: 0,
        dataIndex: 0
      },
      timer: null
    }
  },
  // created() {
  //   this.barLineOptions = getBarLineOptions({ tooltipFormatter: this.tooltipFormatter })
  // },
  mounted() {
    this.barLineDom = document.getElementById(this.domId)
    this[this.domId] = echarts.init(this.barLineDom)
    this.chartBindEvent()
  },
  methods: {
    drawBar(dataList) {
      this.barLineOptions = getBarLineOptions({ seriesData: dataList })
      this.barLineOptions.xAxis.data = dataList.map(item => item.statMonth)
      this.barLineOptions.series[0].data = dataList.map(item => item.channel_zx)
      this.barLineOptions.series[1].data = dataList.map(item => item.channel_qd)
      this[this.domId].setOption(this.barLineOptions)
    },
    chartBindEvent() {
      // resize
      window.addEventListener('resize', () => {
        this[this.domId].resize()
      })
    }
  }
}
</script>

<style scoped lang="scss"></style>