chartConfig.js 1.93 KB
import dayjs from 'dayjs'
export const tooltipConfig = {
  trigger: 'axis',
  borderColor: '#fff',
  backgroundColor: '#fff',
  padding: 8,
  textStyle: {
    color: '#656565',
    fontSize: 12
  },
  extraCssText: 'box-shadow: 0 2px 8px 0 #00000026;',
  // position: function (point, params, dom, rect, size) { // 解决tooltip在最右侧时部分被遮挡
  //   let obj = {};
  //   if (point[0] > size.viewSize[0] / 2) { // 鼠标位置位于echarts容器的一半位置右侧时,提示框显示在左侧
  //     obj['left'] = point[0] - size.contentSize[0] - 20;
  //   } else {
  //     obj['right'] = size.viewSize[0] - size.contentSize[0] * 2;
  //   }
  //   if (point[1] > size.viewSize[1] / 2) { // 鼠标位置位于echarts容器的一半位置下侧时,提示框显示在上侧
  //     obj['top'] = point[1] - size.contentSize[1] - 20;
  //   } else {
  //     obj['bottom'] = size.viewSize[1] - size.contentSize[1] * 2;
  //   }
  //   return obj;
  // }
}
export const xAxisConfig = (params) => {
  let { allYear, dateType } = params.searchTime,
    xaxis = {
      type: 'category',
      boundaryGap: false,
      splitLine: {
        show: false
      },
      axisTick: {
        alignWithLabel: true
      },
      axisLabel: {
        showMaxLabel: true,
        formatter: function (value, index) {
          let str = ''
          str = allYear ? dayjs(value).format('MM月') : dayjs(value).format('MM/DD')
          if (dateType == 1) str = value
          return str

        }
      }
    }
  if (allYear) xaxis.splitNumber = 11
  return xaxis
}

export const dataZoomSliderConfig = (params, timeList) => {
  return {
    type: 'slider',
    left: 100,
    right: 100,
    labelFormatter (value) {
      let { allYear, dateType } = params.searchTime,
      str = allYear ? dayjs(timeList[value]).format('YYYY年MM月') : dayjs(timeList[value]).format('YYYY-MM-DD')
      if(dateType == 1) str = timeList[value]
      return str
    }
  }
}