<template>
  <div class="char">
    <div id="barcircles" 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("barcircles");
  var myChart = echarts.init(chartDom, "dark");
  var option;

  option = {
    backgroundColor: "#fff",
    title: {
      text: "事故事件统计表",
      left: 'center',
      textStyle: {
        color: '#000'
      },
    },
    tooltip: {
      show: true,
      feature: {
        mark: { show: true },
        dataView: { show: true, readOnly: false },
        magicType: { show: true, type: ["line", "bar"] },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    legend: {
      data: ["一般", "较大", "重大", "特大"],
      top: 'bottom', // 设置图例放在底部
      left: 'center', // 设置图例居中
      axisLabel: {
        color: '#000',
      },
    },
    grid: {
      top: "10%",
      left: "3%",
      right: "4%",
      bottom: "8%",
      containLabel: true
    },
    xAxis: {
      type: "category",
      axisLabel: {
        color: '#000',
        interval: 0,//代表显示所有x轴标签显示
        rotate: 10
      },
      data: props.list.map(item => item.orgjc)
    },
    yAxis: {
      type: "value",
      axisLabel: {
        color: '#000',
      },
    },
    series: [{
      name: "一般",
      type: "bar",
      data: props.list.map(item => item.count11)
    },
    {
      name: "较大",
      type: "bar",
      data: props.list.map(item => item.count12)
    },
    {
      name: "重大",
      type: "bar",
      data: props.list.map(item => item.count13)
    },
    {
      name: "特大",
      type: "bar",
      data: props.list.map(item => item.count14)
    }]
  };
  option && myChart.setOption(option);
  window.onresize = function () {
    myChart.resize();
  };
  document.getElementById("barcircles").setAttribute("_echarts_instance_", "");
}
onMounted(() => {
  lineChartFn();
});
</script>

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

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