LineChart.vue 2.55 KB
<!--
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2022-10-25 10:43:46
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2022-10-28 14:53:22
 * @FilePath: \dj-data-view\src\components\barChart.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="line-box">
    <div :id="domId" class="line-chart" :style="{ height: boxHeight }"></div>
  </div>
</template>
<script>
import datas from '@/utils/data'
import * as echarts from 'echarts'
import { getLineOptions,getLineDoubleOptions } from './options'
export default {
  name: 'lineChart',
  props: {
    domId: {
      type: String,
      default: 'line-chart'
    },
    isDouble: {
      type: Boolean,
      default: false
    },
    revese: {
      type: Boolean,
      default: false
    },
    boxHeight: {
      type: String,
      default: '12.83vh'
    },
    storeOrBrandTxt: {
      type: String,
      default: '品牌'
    },
    privateList: {
      type: [Object, Array],
      default: () => {}
    },
    // 0-月表;1-日表
    queryType: {
      type: Number,
      default: 0
    },
    tooltipFormatterObj: {
      type: Array,
      default: () => {
        return [
          {
            label: '数量',
            attrName: 'num'
          },
          {
            label: '环比',
            attrName: 'hrate',
            addSymbol: '%'
          },
          {
            label: '同比',
            attrName: 'trate',
            addSymbol: '%'
          }
        ]
      }
    }
  },
  data() {
    return {
      directionTimer: datas.DefaultData.directionTimer,
      delayTimer: datas.DefaultData.delayTimer,
      rankFlag: 'top',
      lineOptions: [],
      rankList: [],
      echartsLine: '',
      moveAttr: {
        // speed: 900,
        seriesIndex: 0,
        dataIndex: 0
      },
      timer: null
    }
  },
  watch: {
    privateList: {
      handler() {
        this.lineOptions =this.isDouble?getLineDoubleOptions(this.privateList) : getLineOptions(this.privateList)
        this.chartBindEvent()
      },
      deep: true
    }
  },
  mounted() {
    this.lineDom = document.getElementById(this.domId)
    this[this.domId] = echarts.init(this.lineDom)
  },
  methods: {
    chartBindEvent() {
      this[this.domId].setOption(this.lineOptions)
    }
  }
}
</script>
<style lang="scss" scoped>
.line-box {
  height: 100%;
  color: #ffffff;
  .txt-orange {
    color: #eb6001;
  }
  .line-chart {
    width: 100%;
  }
}
</style>