
<template>
  <el-card shadow="always" class="common-card-container common-card-container-body-no-padding">
    <div slot="header">
      <span class="card-title">电量指标</span>
<!--      <el-button style="float: right; padding: 3px 0" type="text" size="small">按年</el-button>-->
    </div>
    <div style="height: 360px" id="dlzbChart"/>
  </el-card>
</template>

<style scoped lang="scss"></style>
<script>
import * as echarts from 'echarts'
import resize from '@/mixins/ems/resize'

export default {
  mixins: [resize],
  data() {
    return {
      chart: null
    }
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(data) {
      this.chart = echarts.init(document.querySelector('#dlzbChart'))
      this.setOption(data)
    },
    setOption(data) {
      const source=[['日期','充电量','放电量']]
      data.forEach(item => {
        source.push([item.dateMonth,item.chargeEnergy,item.disChargeEnergy])
      })
      this.chart.setOption({
        grid: {
          containLabel: true
        },
        legend: {
          left: 'center',
          bottom: '15',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        textStyle:{
          color:"#333333",
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle:{
              color: '#333333',
            }
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            lineStyle:{
              color: '#333333',
            }
          }
        },
        dataset:{source},
        series: [
        {
          name:'充电量',
          type: 'line',
          itemStyle: {
            color: '#F86F70',
            opacity: 0.5
          },
          areaStyle: {
            color: '#F86F70',
            opacity: 0.5
          }
        },{
            name:'放电量',
            type: 'line',
            itemStyle: {
              color: '#488AFF',
              opacity: 0.5
            },
            areaStyle: {
              color: '#488AFF',
              opacity: 0.5
            }
          }]
      })
    }
  }
}

</script>
