import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    grid: {
      top: '8%',
      right: '3%',
      bottom: '3%',
      left: '3%',
      containLabel: true
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: true,
        lineStyle: {
          color: '#e7f3ff',
        }
        
      },
      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: nameList,
      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: valueList,
      label: {
        show: true,
        position: 'top',
        color: 'rgba(5, 95, 194, 1)',
        fontWeight: 'bold',  // 文字加粗
        fontSize: 14,
        formatter: function (params) {
          return params.value
        },
      },
      barWidth: 20,
      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