import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    grid: {
      top: '8%',
      right: '6%',
      bottom: '6%',
      left: '6%',
      containLabel: true
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: false
      },
      show: false
    },
    xAxis: {
      type: 'category',
      data: nameList.map(item => {
        return item.name
      }),
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: true
      }
    },
    series: [{
      type: 'bar',
      data: valueList,
      label: {
        show: true,
        position: 'top',
        textStyle: {
          color: 'rgba(5, 95, 194, 1)',
          fontSize: 16,
          fontWeight: 700,
          fontFamily: 'Microsoft YaHei'
        },
        formatter: function (params) {
          return params.value
        }
      },
      barWidth: 20,
      markPoint: {
        symbol: 'circle',
        symbolSize: 0,
        data: (function () {
          const data = [];
          nameList.forEach((item, index) => {
            data.push({
              name: 'icon',
              // value: '',
              xAxis: index,
              yAxis: valueList[index],
              symbol: `image://${item.img}`,
              symbolSize: [20, 20],
              symbolOffset: [0, 10]
            });
          });
          return data;
        })()
      },
      itemStyle: {
        color: function (params) {
          return new echarts.graphic.LinearGradient(0, 1, 0, 0,
            [{
              offset: 0,
              color: 'rgba(5, 95, 194, 0)'
            },
            {
              offset: 1,
              color: 'rgba(5, 95, 194, 1)'
            }
            ]);
        },
        barBorderRadius: [10, 10, 4, 4],
      }
    }]
  }
  return option
}

export default getBarChart