import * as echarts from "echarts";

const getBarChart = (data) => {
  const option = {
    tooltip: {},
    grid: {
      top: 48,
      right: 34,
      bottom: 10,
      left: 24,
      containLabel: true
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#DEE2E7'],   // 线条颜色，可以是数组，用于不同间隔交替颜色
          width: 1,           // 线宽
          type: 'dashed',     // 类型：'solid'（实线）, 'dashed'（虚线）, 'dotted'（点线）
          // opacity: 0.6        // 透明度
        }
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(95, 101, 108, 1)',
        }
      },
      show: true,
      textStyle: {
        color: 'rgba(95, 101, 108, 1)',
        fontFamily: 'Microsoft YaHei',
        fontsize: 14,
      }
    },
    xAxis: {
      type: 'category',
      data: data.dataX,
      splitLine: {
        show: false
      },
      axisTick: {
        show: true
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#e7f3ff',
        }
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: 'rgba(95, 101, 108, 1)',
          fontFamily: 'Microsoft YaHei',
          fontsize: 14,
        }
      }
    },
    series: [{
      type: 'bar',
      data: data.dataY,
      label: {

        show: true,

        position: 'top',
        color: 'rgb(59, 65, 75)',
        fontWeight: 'regular',  // 文字加粗
        fontSize: 16,
        fontFamily: 'Source Han Sans CN',
        formatter: function (params) {
          return params.value
        },
      },
      barWidth: data.dataX.length < 60 ? 20 : 3,
      itemStyle: {
        color: function (params) {
          return new echarts.graphic.LinearGradient(0, 1, 0, 0,
            [{
              offset: 0,
              color: 'rgba(10, 87, 166, 0)'
            },
            {
              offset: 1,
              color: 'rgba(5, 95, 194, 1)'
            }
            ]);
        },
        // barBorderRadius: 10,
      }
    }]
  }
  return option
}

export default getBarChart