<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: "vertical",
          left: "right",
          bottom: "0",
          itemWidth: 20,
          itemHeight: 10,
          icon: "roundRect",
          textStyle: {
            fontSize: "14px",
            color: "#000",
          },
        },
        // color:'#6e98ed',
        tooltip: {
          trigger: "item",
        },

        grid: {
          left: "3%",
          right: "4%",
          containLabel: true,
        },
        series: [
          {
            name: this.legendName,
            type: "pie",
            radius: "65%",
            data: [
              { value: 1048, name: "部门1" },
              { value: 735, name: "部门2" },
              { value: 580, name: "部门3" },
              { value: 484, name: "部门4" },
              { value: 300, name: "部门5" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
    },
  },
};
</script>

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