<template>
  <div :id="echid" class="gfChart"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: ["datas"],
  watch: {
    datas: {
      handler(val) {
        this.hamdlegfChart();
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      echid: "",
    };
  },
  created() {
    this.echid = "ech_" + new Date().getTime();
  },
  mounted() {
    // this.titles = this.titles
    // this.datas = this.datas
    this.hamdlegfChart();
  },
  methods: {
    hamdlegfChart() {
      if (document.getElementById(this.echid)) {
        let myechart = echarts.init(document.getElementById(this.echid));
        myechart.setOption({
          tooltip: {},
          grid: {
            left: "10",
            right: "20",
            bottom: "0",
            top: "35",
            containLabel: true,
          },
          legend: {
            textStyle: {
              color: "#333",
            },
          },
          xAxis: {
            type: "value",
            splitLine: {
              show: true,
              lineStyle: {
                // color: "#224465",
              },
            },
          },
          yAxis: {
            type: "category",
            data: this.datas.titles,
          },
          series: [
            {
              name: "刑事",
              type: "bar",
              stack: "total",
              label: {
                show: true,
                color: "#fff",
                fontSize: 12,
              },
              emphasis: {
                focus: "series",
              },
              data: this.datas.xsList,
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#015eea",
                    },
                    {
                      offset: 1,
                      color: "#00c0fa",
                    },
                  ],
                },
              ],
            },
            {
              name: "行政",
              type: "bar",
              stack: "total",
              label: {
                show: true,
                color: "#fff",
              },
              emphasis: {
                focus: "series",
              },
              data: this.datas.xzList,
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#b6325f",
                    },
                    {
                      offset: 1,
                      color: "#ff887c",
                    },
                  ],
                },
              ],
            },
            // {
            // 	name: '总数',
            // 	type: 'bar',
            // 	stack: 'total',
            // 	label: {
            // 		show: false,
            // 		color: '#000'
            // 	},
            // 	emphasis: {
            // 		focus: 'series'
            // 	},
            // 	data: this.datas.zsList,
            // 	color: [{
            // 		type: 'linear',
            // 		x: 0,
            // 		y: 0,
            // 		x2: 0,
            // 		y2: 1,
            // 		colorStops: [{
            // 				offset: 0,
            // 				color: '#ecc801'
            // 			},
            // 			{
            // 				offset: 1,
            // 				color: '#feef45'
            // 			}
            // 		]
            // 	}]
            // },
          ],
        });
      }
    },
  },
};
</script>

<style scoped>
.gfChart {
  margin-top: 1vw;
  height: 65vw;
  width: 95vw;
  margin: 0 auto;
}
</style>
