linechart.vue 3.17 KB
<template>
  <div :id="echartId" class="chart-line"></div>
</template>

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

  props: {
    echartId: {
      type: String,
      default: ''
    },
    echartData: {
      type: Array
    }
  },

  data() {
    return {}
  },

  watch: {
    echartData(value) {
      let data
      if (value[0].customerCount == 0 || value[0].customerCount) {
        data = value.map(item => {
          return item.customerCount
        })
      } else {
        data = value.map(item => {
          return item.outputValue
        })
      }
      let dateTime = value.map(item => {
        return item.dateTime
      })
      this.getChartTotal(dateTime, data)
    }
  },

  methods: {
    getChartTotal(dateTime, lineData) {
      var chartDom = document.getElementById(this.echartId)
      var myChart = echarts.init(chartDom)
      var option
      option = {
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: dateTime
        },
        yAxis: {
          type: 'value',
          show: false
        },
        grid: {
          bottom: 0,
          top: 0
        },
        series: [
          {
            data: lineData,
            type: 'line',
            symbol: 'none',
            color: '#5850FF',
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: '#5850FF' // 100% 处的颜色
                  },
                  {
                    offset: 1,
                    color: '#FFFFFF' //   0% 处的颜色
                  }
                ],
                global: false // 缺省为 false
              }
            }
          }
        ]
      }
      myChart.clear();
      option && myChart.setOption(option)
    }
  }
}
</script> 

<style scoped lang="scss">
.chart-line {
  height: 60px;
}
.summary-header {
  display: flex;
  color: #3a3a3a;
  justify-content: space-between;
}
.summary-customer-panel {
  display: flex;
  .summary-item {
    width: 25%;
    box-sizing: border-box;
    padding-right: 20px;
    margin-right: 20px;
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    &:last-of-type {
      border: none;
    }
    .summary-item-title {
      .item {
        background: #ffffff;
        box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
        border: 1px solid #e4e7ed;
      }
      i {
        color: #999999;
        background: none;
      }
    }
    .summary-item-total {
      font-size: 30px;
      color: rgba(0, 0, 0, 0.85);
      line-height: 38px;
      margin: 20px 0px 10px 0px;
    }
    .summary-item-number {
      font-size: 12px;
      font-weight: 400;
      color: #666666;
      line-height: 20px;
      margin-bottom: 20px;
    }
    #main-total {
      height: 60px;
    }
  }
}
.expand-more {
  margin-bottom: 20px;
  text-align: center;
  height: 56px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0px 0px 2px 2px;
  font-size: 14px;
  line-height: 56px;
  color: #000000;
}
#main-customer {
  height: 300px;
}
</style>