<template>
  <div>
    <div :id="id" :style="styleObj"></div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    id: {
      type: String,
      default: "",
    },
    legendName: {
      type: String,
      default: "",
    },
    styleObj: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {};
  },
  watch: {
    title(val) {
      console.log(val);
      this.drawLine();
    },
  },
  mounted() {
    this.drawLine();
  },

  methods: {
    drawLine() {
      // 基于dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById(this.id));
      // 绘制图表
      myChart.setOption({
        title: {
          text: this.title,
          left: this.legendName == "旷工率" ? "center" : "left",
          textStyle: {
            fontSize: this.legendName == "旷工率" ? 24 : 18,
          },
        },
        color:'#6e98ed',
        legend: {
          orient: "horizontal",
          right: "50px",
          top: "0",
          itemWidth: 20,
          itemHeight: 10,
          icon: "roundRect",
          textStyle: {
            fontSize: "14px",
            color: "#000",
          },
        },
        tooltip: {},
        xAxis: {
          data: ["部门1", "部门2", "部门3", "部门4", "部门5", "部门6"],
        },
        grid: {
          left: "5%",
          right: "4%",
          bottom: "2%",
          containLabel: true,
        },
        // color:[ "#61a0a8",],
        yAxis: {},
        series: [
          {
            name: this.legendName,
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
            itemStyle: {
              
              lineStyle: {
                type: "dotted", //'dotted'虚线 'solid'实线
              },
            },
          },
        ],
      });
    },
  },
};
</script>

<style lang="less" scoped></style>
