import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    grid: {
      top: 40,
      right: 64,
      bottom: 24,
      left: 24,
      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,
        textStyle: {
          color: 'rgb(59, 65, 75)',
          fontSize: '16px',
          fontFamliy: 'Source Han Sans CN'
        }
      }
    },
    series: [{
      type: 'bar',
      data: valueList,
      label: {
        show: true,
        position: [434, 0],
        formatter: function (params) {
          return params.value + ' 次'
        },
        textStyle: {
          color: 'rgb(59, 65, 75)',
          fontSize: '16px',
          fontFamliy: 'Source Han Sans CN'
        }
      },
      barWidth: 8,
      itemStyle: {
        color: function (params) {
          return new echarts.graphic.LinearGradient(0, 0, 1, 0,
            [{
              offset: 0,
              color: 'rgb(231, 243, 255)'
            },
            {
              offset: 1,
              color: 'rgb(5, 95, 194)'
            }
            ]);
        },
        barBorderRadius: 4,
      }
    }]
  }
  return option
}

export default getBarChart