BarLineOptions.js 3.94 KB
import * as echarts from 'echarts'
function getBarLineOptions(obj) {
  const { tooltipFormatter } = obj
  var barLineOption = {
    tooltip: {
      trigger: 'axis',
      borderWidth: 0,
      backgroundColor: 'rgba(68,68,68,0.80)',
      textStyle: {
        color: 'rgba(255,255,255,0.6)',
        fontSize: '1.5px'
      },
      formatter: tooltipFormatter || '',
      confine: true
    },
    xAxis: {
      data: []
    },
    yAxis: [
      {
        name: '¥',
        type: 'value',
        min: 0,
        max: 8000,
        axisLabel: {
          formatter: '{value}'
        },
        splitLine: {
          show: false
        }
      },
      {
        name: '',
        type: 'value',
        min: 0,
        max: 100,
        interval: 20,
        axisLabel: {
          formatter: '{value}%'
        },
        splitLine: {
          lineStyle: {
            color: '#1d2a38'
          }
        }
      }
    ],
    grid: {
      left: '3%',
      right: '4%',
      top: '20%',
      bottom: '6%',
      containLabel: true
    },
    series: [
      {
        name: 'bar',
        type: 'bar',
        stack: 'one',
        data: [],
        label: {
          show: true,
          position: 'insideTop',
          color: '#fff'
        },
        itemStyle: {
          barBorderRadius: [2, 2, 0, 0], // 柱体圆角
          color: function(params) {
            const colorList = [
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF'],
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF'],
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF'],
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF'],
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF'],
              ['#22D8FF', '#5C56FF'],
              ['#2AD190', '#00B7DF']
            ]
            var colorItem = colorList[params.dataIndex]
            return new echarts.graphic.LinearGradient(
              0, 0, 0, 1, [{ // 代表渐变色从正上方开始
                offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
                color: colorItem[0]
              }, // 柱图渐变色
              {
                offset: 1, // 指100%处的颜色
                color: colorItem[1]
              }]
            )
          }
        }
      },
      {
        name: 'bar2',
        type: 'bar',
        stack: 'one',
        label: {
          show: true,
          position: 'insideTop',
          color: '#fff'
        },
        data: [],
        itemStyle: {
          barBorderRadius: [2, 2, 0, 0], // 柱体圆角
          color: function(params) {
            const colorList = [
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972'],
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972'],
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972'],
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972'],
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972'],
              ['#11627A', '#282F7A'],
              ['#145F4E', '#035972']
            ]
            var colorItem = colorList[params.dataIndex]
            return new echarts.graphic.LinearGradient(
              0, 0, 0, 1, [{ // 代表渐变色从正上方开始
                offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
                color: colorItem[0]
              }, // 柱图渐变色
              {
                offset: 1, // 指100%处的颜色
                color: colorItem[1]
              }]
            )
          }
        }
      },
      {
        name: 'Dynamic Line',
        type: 'line',
        yAxisIndex: 1,
        data: []
      }
    ]
  }
  return barLineOption
}

export default getBarLineOptions