import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    grid: {
      top: '3%',
      right: '3%',
      bottom: '1%',
      left: '1%',
      containLabel: true
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      show: true
    },
    xAxis: {
      type: 'category',
      data: nameList,
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: true
      },
      axisLabel: {
        show: true
      }
    },
    series: [{
      type: 'bar',
      data: valueList,
      label: {
        show: true,
        position: 'top',
        color: 'rgba(10, 87, 166, 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(10, 87, 166, 1)'
            }
            ]);
        },
        barBorderRadius: 10,
      }
    }]
  }
  return option
}

export default getBarChart