<template>
  <div class="char">
    <div id="lincircles" style="width: 100%; height: 100%"></div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref, onMounted, watch, defineProps } from "vue";
const props = defineProps({
  key: Number,
  list: { type: Array }
});
watch(
  () => props.key,
  () => {
    lineChartFn();
  },
  {
    deep: true
  }
);


function lineChartFn() {
  var chartDom = document.getElementById("lincircles");
  var myChart = echarts.init(chartDom, "dark");
  var option;

  option = {
    backgroundColor: "#fff",
    title: {
      text: '事故趋势图（年份）',
      left: 'center',
      textStyle: {
        color: '#000'
      },
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: 'bottom', // 设置图例放在底部
    },
    toolbox: {
      show: true,
      feature: {
        dataZoom: {
          yAxisIndex: 'none'
        },
        dataView: { readOnly: false },
        magicType: { type: ['line', 'bar'] },
        restore: {},
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisLabel: {
        color: '#000',
      },
      data: props.list.yearList
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        color: '#000',
        formatter: '{value}'
      }
    },
    series:
      props.list.resList

  };
  option && myChart.setOption(option);
  window.onresize = function () {
    myChart.resize();
  };
  document.getElementById("lincircles").setAttribute("_echarts_instance_", "");
}
onMounted(() => {
  lineChartFn();
});
</script>

<style lang="scss" scoped>
.char {
  width: 100% !important;
  height: 320px !important;
}

.canvas {
  background-color: #fff !important;
}
</style>
