<template>
  <div :id="domId" style="height: 100%;"></div>
</template>

<script>
import { generateUUID } from '@/utils/index'
export default {
  name: 'line-chart',
  props: {
    dataItem: {
      type: Array,
      default: () => {}
    }
  },
  data () {
    return {
      domId: generateUUID(),
      chart: null,
      option: {
        title: {
          text: '历年不良率',
          top: '5',
          textStyle: {
            fontWeight: 'normal',
            fontSize: 16,
            color: '#0D47A1'
          }
        },
        grid: {
          top: '50',
          bottom: '30',
          left: '50',
          right: '50'
        },
        xAxis: {
          type: 'category',
          data: ['2017', '2018', '2019', '2020', '2021', '2022', '2023']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [],
            type: 'line',
            lineStyle: {
              color: '#f30'
            },
            itemStyle: {
              color: '#f30'
            }
          }
        ]
      }
    }
  },
  created () {
    this.option.series[0].data = this.dataItem
  },
  mounted () {
    this.initMap()
    this.chart.on('click', (param) => {
      this.$emit('click', param)
    })
  },
  methods: {
    initMap () {
      this.chart = this.$echarts.init(document.getElementById(this.domId), null, { renderer: 'svg' })
      this.chart.setOption(this.option)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
