<template>
  <div>
    <div id="circlecz" style="width: 1000px; height: 260px"></div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref, onMounted, watch, defineProps } from "vue";
const props = defineProps({
  data: {
    type: Array,
    default: []
  }
});
watch(
  () => props.data,
  () => {
    lineChartFn();
  }
);
function lineChartFn() {
  var chartDom = document.getElementById("circlecz");
  var myChart = echarts.init(chartDom);
  var option;
  var salvProName = props.data.map((item) => item.name);
  var salvProValue = props.data.map((item) => item.sl);

  option = {
    grid: {
      left: "3%",
      right: "5%",
      bottom: "10%",
      top: "10%",
      containLabel: true
    },
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "none"
      },
      formatter: function (params) {
        return params[0].name + " : " + params[0].value;
      }
    },
    xAxis: {
      show: true,
      splitLine: {
        show: true,
        textStyle: {
          color: "#ddd"
        },
        lineStyle: {
          color: "rgba(255,255,255,0.12)"
          // type: "dashed"
        }
      },
      axisLine: {
        show: true,
        textStyle: {
          color: "#ddd"
        },
        lineStyle: {
          color: "rgba(255,255,255,0.12)"
          // type: "dashed"
        }
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        margin: 10,
        color: "#ddd",
        textStyle: {
          fontSize: 14
        }
      },
      type: "value"
    },
    yAxis: [
      {
        type: "category",
        inverse: true,
        boundaryGap: true,
        axisLabel: {
          show: true,
          color: "#ddd",
          lineStyle: {
            color: "rgba(255,255,255,0.12)"
          }
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: false
        },
        data: salvProName
      }
    ],
    series: [
      {
        // name: '值',
        type: "bar",
        zlevel: 1,
        itemStyle: {
          normal: {
            barBorderRadius: [0, 10, 10, 0],
            // color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
            //   {
            //     offset: 0,
            //     color: "rgb(57,89,255,1)"
            //   },
            //   {
            //     offset: 1,
            //     color: "rgb(46,200,207,1)"
            //   }
            // ])
          }
        },
        label: {
          normal: {
            show: true
          },
          position: "right"
        },
        barWidth: 10,
        data: salvProValue
      }
    ]
  };

  option && myChart.setOption(option);
  window.onresize = function () {
    myChart.resize();
  };
  document.getElementById("circlecz").setAttribute("_echarts_instance_", "");
}
onMounted(() => {
  lineChartFn();
});
</script>

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