options.js 5.84 KB
/*
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-09-14 14:08:14
 * @LastEditors: yangming yangming@didihu.com.cn
 * @LastEditTime: 2023-10-12 14:58:59
 * @FilePath: \scrm-micro-home\src\components\options.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as echarts from 'echarts'
import util from '@/utils/util'
function getLineOptions(obj) {
  const { color, lineList } = obj
  //   const statDate = dataList.map(item => item.statDate)
  const dataList = lineList.map(item => +item.ordinateValue || +item.output || 0)
  console.log(dataList, 'dataList')
  // 定义颜色渐变
  var gradientColors = [
    {
      offset: 0, // 渐变起始位置
      color: color[0] // 渐变起始颜色
    },
    {
      offset: 1, // 渐变结束位置
      color: color[1] // 渐变结束颜色
    }
  ]
  const num = dataList.map((item, index) => {
    return {
      value: item,
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
        }
      }
    }
  })

  console.log(num)
  var options = {
    xAxis: {
      type: 'category',
      axisLabel: {
        show: false // 隐藏 y 轴坐标标签
      },
      axisTick: {
        show: false // 隐藏 y 轴刻度线
      },
      data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    },
    grid: {
      bottom: 0,
      top: 0
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        show: false // 隐藏 y 轴坐标标签
      },
      splitLine: false,
      axisTick: {
        show: false // 隐藏 y 轴刻度线
      }
    },
    series: [
      {
        barWidth: '50%', // 柱条宽度
        data: num,
        // itemStyle: {
        //   normal: {
        //     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
        //   }
        // },
        type: 'bar'
      }
    ]
  }
  return options
}
function getLineOddOptions(obj) {
  const { color, lineList } = obj
  console.log(obj)
  //   const statDate = dataList.map(item => item.statDate)
  const dataList = lineList.map(item => item.saleAmount)
  const dataX = lineList.map(item => item.aggregateTime)
  // 定义颜色渐变
  var gradientColors1 = [
    {
      offset: 0, // 渐变起始位置
      color: color[0] // 渐变起始颜色
    },
    {
      offset: 1, // 渐变结束位置
      color: color[1] // 渐变结束颜色
    }
  ]
  var gradientColors2 = [
    {
      offset: 0, // 渐变起始位置
      color: color[2] // 渐变起始颜色
    },
    {
      offset: 1, // 渐变结束位置
      color: color[3] // 渐变结束颜色
    }
  ]
  const num = dataList.map((item, index) => {
    return {
      value: item
      // itemStyle: {
      //   normal: {
      //     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, index % 2 == 0 ? gradientColors1 : gradientColors2) // 设置渐变色
      //   }
      // }
    }
  })
  var options = {
    xAxis: {
      type: 'category',
      // axisLabel: {
      //   show: false // 隐藏 y 轴坐标标签
      // },
      axisTick: {
        show: false // 隐藏 y 轴刻度线
      },
      data: dataX
    },
    tooltip: {
      trigger: 'axis', // 设置触发类型为坐标轴轴线触发
      axisPointer: {
        type: 'line' // 设置指示器类型为直线
      },
      formatter: function(params) {
        const value = params[0].value
        return `销售额<br><b>¥${util.formatNumber(value)}</b>`
      }
    },
    grid: {
      bottom: '10%',
      top: '8%'
    },
    // 其他配置项...
    dataZoom: [
      {
        type: 'slider', // 显示滑动条
        xAxisIndex: 0, // 指定水平拖动的 x 轴索引
        start: 0, // 初始的数据窗口范围的起始位置
        end: 100 // 初始的数据窗口范围的结束位置
        // dataBackground: {
        //   lineStyle: {
        //     width: 10, // 滑动柱的宽度
        //     color: '#ff0000' // 滑动柱的颜色
        //   }
        // }
      }
    ],
    yAxis: {
      type: 'value',
      axisLabel: {
        formatter: function(value) {
          if (value === 0) {
            return ''
          } else {
            return value
          }
        }
      }
    },
    series: [
      {
        barWidth: '35%', // 柱条宽度
        data: num,
        // itemStyle: {
        //   normal: {
        //     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
        //   }
        // },
        type: 'line',
        areaStyle: {
          color: 'rgba(211, 208, 255, 1)' // 设置面积颜色和透明度
        }
      }
    ]
  }
  return options
}
function getPieOptions(obj) {
  console.log(obj, 888)
  const color = obj.map(item => item.color)
  const dataList = obj.map(item => {
    return {
      value: item.saleAmount
    }
  })
  var options = {
    color,
    series: [
      {
        name: '',
        type: 'pie',
        // center: ['50%', '53%'],

        radius: ['60%', '80%'],
        label: {
          show: false, // 不显示标签
          position: 'center'
        },
        emphasis: {
          scale: true, // 不放大扇区,
          label: {
            show: true,
            formatter: function(params) {
              return '{a|销售额}\n{b|¥' + util.formatNumber(params.value) + '}'
            },
            rich: {
              a: {
                fontSize: 12,
                lineHeight: 24
              },
              b: {
                fontSize: 20,
                lineHeight: 30
              }
            }
          }
        },
        labelLine: {
          show: false // 不显示标签引导线
        },
        data: dataList
      }
    ]
  }
  return options
}
export default { getLineOptions, getLineOddOptions, getPieOptions }