import * as echarts from 'echarts'

const getMultiLineChart = (dataX, dataY1, dataY2) => {
  // let maxVal = Math.max(...(dataY1 || [0]), ...(dataY2 || [0]))
  // if (maxVal === 0) maxVal = 100
  // else maxVal = maxVal * 1.2
  // let interval = Math.ceil(maxVal / 5)
  // if (interval > 5) interval = Math.ceil(interval / 10) * 10
  // maxVal = interval * 5
  return {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    grid: {
      top: '5%',
      right: '3%',
      bottom: '3%',
      left: '3%',
      containLabel: true
    },
    legend: {
      data: ['提出法案', '通过法案'],
      show: false
    },
    color: ['#1459bb', '#fa8c16'],
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        data: dataX
      }
    ],
    yAxis: [
      {
        type: 'value',
        splitNumber: 5,
        alignTicks: false
      }
    ],
    series: [
      {
        name: '提出法案',
        type: 'line',

        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(22, 119, 255, 1)' // 起始颜色
          }, {
            offset: 1,
            color: 'rgba(22, 119, 255, 0)' // 结束颜色
          }])
        },
        emphasis: {
          focus: 'series'
        },
        data: dataY1
      },
      {
        name: '通过法案',
        type: 'line',
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(255, 172, 77, 1)' // 起始颜色
          }, {
            offset: 1,
            color: 'rgba(255, 172, 77, 0)' // 结束颜色
          }])
        },
        emphasis: {
          focus: 'series'
        },
        data: dataY2
      }
    ]
  }
}

export default getMultiLineChart