import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    grid: {
      top: '3%',
      right: '3%',
      bottom: '1%',
      left: '1%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      splitLine: {
        show: false
      },
      show: false
    },
    yAxis: {
      type: 'category',
      data: nameList,
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: true
      }
    },
    series: [{
      type: 'bar',
      data: valueList,
      label: {
        show: true,
        position: [610, 0],
        formatter: function (params) {
          return params.value + ' 次'
        }
      },
      barWidth: 8,
      itemStyle: {
        color: function (params) {
          return new echarts.graphic.LinearGradient(0, 0, 1, 0,
            [{
              offset: 0,
              color: 'rgba(255,255,255,0)'
            },
            {
              offset: 1,
              color: '#1778ff'
            }
            ]);
        },
        barBorderRadius: 4,
      }
    }]
  }
  return option
}

export default getBarChart