import * as echarts from "echarts";

const getBarChart = (nameList, valueList) => {
  const option = {
    tooltip: {},
    title: {
      text: '单位：万人',
      left: 660,
      top: 10,
      textStyle: {
        color: 'rgba(95, 101, 108, 1)',
        fontSize: 14,
        fontFamily: 'Microsoft YaHei',
        fontstyle: 'Regular',
        fontWeight: 'normal'
      }
    },
    grid: {
      top: '5%',
      right: '3%',
      bottom: '1%',
      left: '1%',
      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