LineChart.vue 1.97 KB
<template>
  <div class="line-box">
    <p v-if="title" class="title">{{ title }}</p>
    <div id="line-chart" class="line-chart"></div>
    <div class="rank-box">
      <div>
        <p :class="[ 'rank-title', rankFlag == 'first' ? 'rank-active' : '' ]" @click="handleRankChange('first')">前5{{ storeOrBrandTxt }}</p>
        <p :class="[ 'rank-title', rankFlag == 'last' ? 'rank-active' : '' ]" @click="handleRankChange('last')">后5{{ storeOrBrandTxt }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import options from './lineOptions'
export default {
  name: 'LineChart',

  props: {
    // height: {
    //   type: String,
    //   default: '19.8vh'
    // },
    apiName: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    },
    storeOrBrandTxt: {
      type: String,
      default: '门店'
    }
  },

  data() {
    return {
      // first,last
      rankFlag: 'first',
      lineOptions: JSON.parse(JSON.stringify(options))
      // chartHeight: this.height
    }
  },

  created() {

  },

  mounted() {
    this.drawLine()
  },

  methods: {
    drawLine() {
      var lineDom = document.getElementById('line-chart')
      var lineChart = echarts.init(lineDom)
      lineChart.setOption(this.lineOptions)
    },

    handleRankChange(value) {
      this.rankFlag = value
    }
  }
}
</script>

<style lang="scss" scoped>
p {
  margin: 0 0;
}
.line-box {
  color: #ffffff;
  padding: 4px 8px;
  font-size: 0.75em;
  .title {
    height: 17px;
    color: #e8e8e8;
  }
  .line-chart {
    height: calc(100% - 25px - 30px);
  }
  .rank-box {
    display: flex;
    height: 30px;
    .rank-title {
      box-sizing: border-box;
      font-size: 0.6em;
      background: #353535;
      padding: 1px 5px;
      height: 15px;
      line-height: 15px;
      opacity: 0.7;
      cursor: pointer;
    }
    .rank-active {
      opacity: 1;
      color: #ffffff;
      background: #eb6001;
    }
  }
}
</style>