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: false,
        position: 'top',
        formatter: function (params) {
          return params.value + ' 次'
        }
      },
      barWidth: 12,
      itemStyle: {
        color: function (params) {
          return new echarts.graphic.LinearGradient(0, 1, 0, 0,
            [{
              offset: 0,
              color: 'rgba(22, 119, 255, 0)'
            },
            {
              offset: 1,
              color: 'rgba(22, 119, 255, 1)'
            }
            ]);
        },
        barBorderRadius: 6,
      }
    }]
  }
  return option
}

export default getBarChart