options.js 5.29 KB
/*
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-09-14 14:08:14
 * @LastEditors: yangming yangming@didihu.com.cn
 * @LastEditTime: 2023-10-08 16:23:48
 * @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'
function getLineOptions(obj) {
  const { color, lineList } = obj
  //   const statDate = dataList.map(item => item.statDate)
  const dataList = lineList.map(item => item.ordinateValue || 0)
  // 定义颜色渐变
  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>¥${value}</b>`
      }
    },
    grid: {
      bottom: '10%',
      top: '8%'
    },
    // 其他配置项...
    dataZoom: [
      {
        type: 'slider', // 显示滑动条
        xAxisIndex: 0, // 指定水平拖动的 x 轴索引
        start: 0, // 初始的数据窗口范围的起始位置
        end: 100 // 初始的数据窗口范围的结束位置
      }
    ],
    yAxis: {
      type: '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: ['80%', '60%'],
        label: {
          show: false, // 不显示标签
          position: 'center'
        },
        emphasis: {
          scale: false, // 不放大扇区,
          label: {
            show: true,
            formatter: ['销售额', '{c|{c}}'].join('\n'),
            rich: {
              b: {
                fontSize: 12,
                lineHeight: 24
              },
              c: {
                fontSize: 24,
                lineHeight: 36
              }
            }
          }
        },
        labelLine: {
          show: false // 不显示标签引导线
        },
        data: dataList
      }
    ]
  }
  return options
}
export default { getLineOptions, getLineOddOptions, getPieOptions }