options.js 8.18 KB
/*
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2022-10-25 10:46:24
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2022-10-31 16:41:32
 * @FilePath: \dj-data-view\src\components\barOptions.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import utils from '../utils/util'
function getBarOptions(obj) {
  const { analysisList, rotate } = obj
  const num = analysisList.map(item => item.ratio * 100)
  console.log(num)
  const name = analysisList.map(item => item.name)
  var options = {
    xAxis: {
      type: 'category',
      axisLabel: {
        color: '#fff',
        fontSize: '0.72em'
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: name
    },
    grid: {
      left: '6%',
      right: '6%',
      top: '6%',
      bottom: '4%',
      // bottom: obj.rotate ? '4%' : '12%',
      containLabel: true
    },
    yAxis: {
      type: 'value',
      splitLine: {
        lineStyle: {
          color: '#2F314F'
        }
      },
      axisLabel: {
        color: '#fff',
        fontSize: '0.75em',
        formatter: '{value}%'
      },
      splitNumber: 4
    },
    series: [
      {
        type: 'bar',
        symbol: 'circle',
        backgroundStyle: {
          color: '#6578FF'
        },
        barWidth: '35%',
        data: num
      }
    ]
  }
  return options
}
function getBarReverseOptions(obj) {
  const { analysisList, ValueAnalysis } = obj
  // const value = Object.values(analysisList)
  const entries = Object.entries(analysisList)
  ValueAnalysis.forEach(sis => {
    entries.forEach(key => {
      if (sis.name == key[0]) {
        sis.value = key[1]
      }
    })
  })
  const value = utils.deepClone(ValueAnalysis).sort((a, b) => b.order - a.order)
  var options = {
    tooltip: {
      trigger: 'axis',
      showContent: false,
      axisPointer: {
        type: 'shadow',
        shadowStyle: {
          color: 'rgba(210, 210, 210, 0.2)'
        }
      },
      borderWidth: 0,
      backgroundColor: 'rgba(68,68,68,0.80)',
      confine: true,
      textStyle: {
        color: '#ffffff',
        fontSize: 8
      }
    },
    yAxis: {
      type: 'category',
      axisLabel: {
        color: '#ccc',
        fontSize: '0.8em'
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: value.map(item => item.label)
    },
    grid: {
      left: '8%',
      right: '0%',
      top: '0%',
      bottom: '0%',
      containLabel: true
    },
    xAxis: {
      nameGap: 30,
      type: 'value',
      splitLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      splitNumber: 4
    },
    series: [
      {
        type: 'bar',
        symbol: 'circle',
        backgroundStyle: {
          color: '#6578FF'
        },
        itemStyle: {
          normal: {
            label: {
              show: true,
              position: 'center',
              textStyle: {
                fontSize: 10,
                color: '#fff',
                height: 16,
                padding: [0, 2, 2, 4],
                lineHeight: 16
              }
            }
          }
        },
        data: value.map(item => item.value)
      }
    ]
  }
  return options
}
function getLineOptions(obj) {
  const { dataList, name } = obj
  const statDate = dataList.map(item => item.statDate)
  const num = dataList.map(item => item.num)
  var options = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          type: 'solid'
        }
      },
      padding: 5,
      borderWidth: 0.5,
      backgroundColor: 'rgba(35, 45, 152, 1)',
      borderRadius: 4,
      textStyle: {
        color: 'rgba(255,255,255,1)',
        fontSize: 10
      },
      formatter: function (item) {
        return `${name}:${item[0].value}`
      }
    },
    xAxis: {
      type: 'category',
      axisLabel: {
        color: '#fff',
        fontSize: '0.7em',
        rotate: 30
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      data: statDate
    },
    grid: {
      left: '6%',
      right: '6%',
      top: '14%',
      bottom: '3%',
      containLabel: true
    },
    yAxis: {
      nameGap: 30,
      type: 'value',
      splitLine: {
        lineStyle: {
          color: '#2F314F'
        }
      },
      axisLabel: {
        color: '#ccc',
        fontSize: '0.7em'
      },
      splitNumber: 4
    },
    series: [
      {
        type: 'line',
        symbol: 'circle',
        itemStyle: {
          color: '#F5AA01'
        },
        // 平滑曲线
        smooth: true,
        showSymbol: false,
        // 折线背景色
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(254, 84, 0, 0.3)'
              },
              {
                offset: 1,
                color: 'rgba(254, 84, 0, 0.01)'
              }
            ]
          }
        },
        data: num
      }
    ]
  }
  return options
}
function lineAndBarOptions(list) {
  const statDate = list.map(item => item.statDate)
  const totalNum = list.map(item => item.totalNum)
  const increNum = list.map(item => item.increNum)
  var options = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          type: 'solid'
        }
      },
      padding: 5,
      borderWidth: 1,
      backgroundColor: 'rgba(35, 45, 152, 1)',
      borderRadius: 4,
      textStyle: {
        color: 'rgba(255,255,255,1)',
        fontSize: 10
      },
      formatter: function (item) {
        const items = list[item[0].dataIndex]
        return `当月总门店数:${item[0].value}<br>当月新增:${item[1].value}<br>上月总门店数:${items.yesterdaytotalNum}<br>上月月新增:${items.yesterdayincreNum}`
      }
    },
    xAxis: [
      {
        type: 'category',
        axisLabel: {
          color: '#fff',
          fontSize: '0.8em'
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: false
        },
        data: statDate
      }
    ],
    grid: {
      left: '3%',
      right: '6%',
      top: '6%',
      bottom: '0%',
      containLabel: true
    },
    yAxis: [
      {
        name: 'bar',
        nameGap: 30,
        type: 'value',
        splitLine: {
          lineStyle: {
            color: '#2F314F'
          }
        },
        axisLabel: {
          color: '#FFD241',
          fontSize: '0.8em'
        },
        splitNumber: 4
      },
      {
        name: 'line',
        nameGap: 30,
        type: 'value',
        splitLine: {
          lineStyle: {
            color: '#2F314F'
          }
        },
        axisLabel: {
          color: '#769EFF',
          fontSize: '0.8em'
        },
        splitNumber: 4
      }
    ],
    series: [
      {
        name: 'line',
        type: 'line',
        symbol: 'circle',
        itemStyle: {
          color: '#F5AA01'
        },
        // 平滑曲线
        smooth: true,
        showSymbol: false,
        // 折线背景色
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(254, 84, 0, 0.3)'
              },
              {
                offset: 1,
                color: 'rgba(254, 84, 0, 0.01)'
              }
            ]
          }
        },
        data: totalNum
      },
      {
        name: 'bar',
        type: 'bar',
        symbol: 'circle',
        backgroundStyle: {
          color: '#6578FF'
        },
        yAxisIndex: 1,
        barWidth: '30%',
        data: increNum
      }
    ]
  }
  return options
}
export { getBarReverseOptions, getBarOptions, lineAndBarOptions, getLineOptions }