<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);
    },
  },
  mounted() {
    this.drawLine();
  },

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

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