DoubleBarOptions.js 3.16 KB
import * as echarts from 'echarts'
import utils from '../../../utils/util'
function getBarLineOptions(obj) {
  const { tooltipFormatter, seriesData } = obj
  var barLineOption = {
    tooltip: {
      trigger: 'axis',
      borderWidth: 0,
      padding: 0,
      backgroundColor: '#051526',
      formatter: tooltipFormatter || ''
    },
    xAxis: {
      data: []
    },
    yAxis: {
      name: '',
      type: 'value',
      // min: 0,
      // max: 100,
      splitLine: {
        lineStyle: {
          color: '#1d2a38'
        }
      },
      splitNumber: 4
    },
    grid: {
      left: '3%',
      right: '2%',
      top: '20%',
      bottom: '6%',
      containLabel: true
    },
    series: [
      {
        name: 'bar',
        type: 'bar',
        stack: 'one',
        data: [],
        label: {
          show: true,
          position: 'top',
          color: '#fff',
          formatter: params => {
            params.value ? utils.numAddSymbol(params.value) : ''
            return params.value
          }
        },
        itemStyle: {
          barBorderRadius: [2, 2, 0, 0], // 柱体圆角
          color: function (params) {
            // const colorList = [
            //   ['#22D8FF', '#5C56FF'],
            //   ['#2AD190', '#00B7DF']
            // ]
            const colorList = ['#22D8FF', '#5C56FF']
            // var colorItem = []
            // colorItem = params.dataIndex % 2 === 0 ? colorList[0] : colorList[1]
            return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                // 代表渐变色从正上方开始
                offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
                color: colorList[0]
              }, // 柱图渐变色
              {
                offset: 1, // 指100%处的颜色
                color: colorList[1]
              }
            ])
          }
        }
      },
      {
        name: 'bar2',
        type: 'bar',
        stack: 'one',
        min: 100,
        label: {
          show: true,
          position: 'top',
          color: '#fff',
          formatter: params => {
            params.value ? utils.numAddSymbol(params.value) : ''
            return params.value
          }
        },
        data: [],
        itemStyle: {
          barBorderRadius: [2, 2, 0, 0], // 柱体圆角
          color: function (params) {
            // const colorList = [
            //   ['#11627A', '#282F7A'],
            //   ['#145F4E', '#035972']
            // ]
            const colorList = ['#11627A', '#282F7A']
            // var colorItem = []
            // colorItem = params.dataIndex % 2 === 0 ? colorList[0] : colorList[1]
            return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                // 代表渐变色从正上方开始
                offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
                color: colorList[0]
              }, // 柱图渐变色
              {
                offset: 1, // 指100%处的颜色
                color: colorList[1]
              }
            ])
          }
        }
      }
    ]
  }
  return barLineOption
}

export default getBarLineOptions