import * as echarts from "echarts";
const getColumnChart = (nameList, valueList, isPer) => {
  const colorList = ['#0958D9', '#0958D9']
  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,
        rotate: 45,                // ① 文字 45°
        color: '#666',
        fontSize: 12
      }
    },
    yAxis: {
      type: 'value',
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: { show: true, color: '#666' }, // ② Y 轴文字
      splitLine: {                             // ③ 横向参考线
        show: true,
        lineStyle: { color: '#ebebeb', width: 1 }
      }
    },
    series: [{
      type: 'bar',
      data: valueList.map((v, i) => ({
        value: v,
        label: { show: false, position: 'top', color: i < 3 ? colorList[0] : colorList[1] }
      })),
      barWidth: 16,
      itemStyle: {
        borderRadius: [8, 8, 0, 0],
        color: params => {
          const colors = params.dataIndex < 3
            ? [colorList[0], 'rgba(255,255,255,0)']
            : [colorList[1], '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