<template>
  <div class="main">
    <div
      class="chart"
      ref="chart"
    >
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  props: {
    dataList: {
      type: Array,
      default: []
    },
    bColor: {
      type: String,
      default: ''
    },
    lineColor: {
      type: String,
      default: ''
    }
  },
  watch: {
    dataList: function(val) {
      if (val.length > 0) {
        this.init()
      }
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      const myChart = this.chart || echarts.init(this.$refs.chart);
      let option = {
        xAxis: {
          type: 'category',
          boundaryGap: false,
        },
        yAxis: {
          type: 'value',
          min: 0,
          max: 100
        },
        grid: {
          left: 28,
          right: 28,
          top: 33,
          bottom: 46
        },
        series: [{
          data: this.dataList,
          type: 'line',
          areaStyle: {
            color: this.bColor
          },
          symbol: 'none',
          lineStyle: {
            color: this.lineColor
          }
        }]
      };

      myChart.setOption(option);
      this.chart = myChart
    }
  }
}
</script>

<style lang="scss" scoped>
.main {
  height: 280px;
  width: 100%;
  .chart {
    width: 100%;
    height: 100%;
  }
}
</style>