import * as echarts from "echarts";
const getColumnChart = (nameList, valueList, isPer) => {
  const colorList = ['rgb(46, 165, 255)']

  return {
    tooltip: {},
    grid: { top: '10%', right: '3%', bottom: '15%', left: '3%', containLabel: true },
    color: colorList,
    xAxis: {
      type: 'category',
      data: nameList,
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: {
        show: true,
        color: '#666',
        fontSize: 14
      }
    },
    yAxis: {
      type: 'value',
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: { show: true, color: '#666' }, // ② Y 轴文字
      splitLine: {
        show: true, lineStyle: {
          type: "dashed",
          color: "#E7F3FF"
        }
      }
    },


    series: [{
      type: 'bar',
      data: valueList.map((v, i) => ({
        value: v,
        label: { show: false, position: 'top', color: 'rgb(46, 165, 255)' }
      })),
      barWidth: 16,
      itemStyle: {
        borderRadius: [8, 8, 0, 0],
        color: params => {
          const colors = ['rgb(46, 165, 255)', 'rgba(255,255,255,0)']
          return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: colors[0] },
            { offset: 1, color: colors[1] }
          ])
        }
      },
      label: {
        show: true,
        position: 'top',
        formatter: v => (isPer ? v.value + '%' : v.value)
      }
    }]
  }
}

export default getColumnChart