<template>
  <custom-echart-bar :chart-data="state.data" height="100%" :option="state.option" />
</template>
<script setup>
import { reactive } from 'vue';

const state = reactive({
  data: [
    { value: 20, name: '耿马镇' },
    { value: 15, name: '勐撒镇' },
    { value: 12, name: '勐永镇' },
    { value: 16, name: '孟定镇' },
    { value: 8, name: '勐简乡' },
    { value: 12, name: '贺派乡' },
    { value: 10, name: '四排山乡' },
    { value: 9, name: '芒洪乡' },
    { value: 8, name: '大兴乡' },
  ],
  option: {
    grid: {
      left: '5%',
      right: '5%',
      bottom: '5%',
      top: '10%',
      containLabel: true,
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow',
      },
      formatter: (data) => {
        const params = data[0];
        let str = `<div class="custom-echarts-tips">
          <span>${params.name}</span><br/>
          <span>${params.marker} ${params.data} 万亩</span>
        </div>`;
        return str;
      },
    },
    barStyle: {
      barWidth: 14,
      itemStyle: {
        borderWidth: 14,
        borderRadius: [8, 8, 8, 8], // 设置柱子的圆角半径
      },
      color: {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          { offset: 0, color: '#35D0C0' },
          { offset: 1, color: '#35D0C0' },
        ],
        global: false,
      },
    },
    xAxis: {
      type: 'value',
      splitLine: {
        show: false,
        lineStyle: {
          type: 'dashed',
          color: '#E5E5E5',
        },
      },
      axisLabel: {
        show: false,
        textStyle: {
          color: '#424242',
        },
      },
      show: false,
      axisLine: {
        show: true,
      },
      axisTick: {
        show: false,
      },
    },
    yAxis: {
      type: 'category',
      data: ['耿马镇', '勐撒镇', '勐永镇', '孟定镇', '勐简乡', '贺派乡', '四排山乡', '芒洪乡', '大兴乡'],
      axisTick: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisLine: {
        show: false,
      },
    },
    series: [
      {
        type: 'bar',
        // barWidth: '40%', // 设置柱的宽度
        // barMinHeight: 2, // 设置柱的最小高度
        // barGap: '20%', // 设置柱之间的间隙
      },
    ],
  },
});
</script>
