Echarts 最大值,最小值,平均值,标注及位置调整

import { MarkPointComponent, MarkLineComponent } from 'echarts/components'
echarts.use([MarkPointComponent, MarkLineComponent])

 如果你已经引入echarts ,却无法显示平均值的线,请尝试引入上述组件

 let obj2 = {
    date: ['2023/07/31', '2023/07/31', '2023/07/31', '2023/07/31', '2023/07/31', '2023/07/31'],
    data: [7, 8, 9, 3, 2, 1]
  }
  handleOption_1_2(obj2)
function handleOption_1_2(data) {
  config.option_1_2 = {
    title: {
      text: '新增当量趋势'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        // 坐标轴指示器,坐标轴触发有效
        type: 'line' // 默认为直线,可选为:'line' | 'shadow'
      }
    },
    xAxis: {
      type: 'category',
      data: data.date,
      axisLabel: {
        interval: 0,
        rotate: 30
        // textStyle: {
        //   color: 'white' // 设置横坐标文字颜色为红色
        // }
      }
    },
    yAxis: {
      type: 'value',
      splitLine: {
        show: false
      }
    },
    series: [
      {
        data: data.data,
        type: 'line',
        markLine: {
          symbol: ['none', 'none'],
          data: [
            {
              type: 'average',
              name: '平均值',
              lineStyle: {
                //标注线样式
                normal: {
                  type: 'dotted',
                  color: '#000' //标注线颜色
                }
              },
              label: {
                show: true,
                position: 'middle', // 表现内容展示的位置
                formatter: '{a|平均值 : }{b|{c}}', // 标线展示的内容
                rich: {
                  a: {
                    // fontSize: '20px'
                    backgroundColor: 'transparent'
                  },
                  b: {
                    backgroundColor: 'transparent'
                  }
                }
              }
            },

            {
              type: 'max',
              name: '最大值',
              // symbol: ['none', 'none'],
              lineStyle: {
                //标注线样式
                normal: {
                  type: 'dotted',
                  color: '#000' //标注线颜色
                }
              },
              label: {
                show: true,
                position: 'left',
                formatter: '{a|上限(UCL) : }{b|{c}}',
                rich: {
                  a: {
                    backgroundColor: 'transparent',
                    color: '#000'
                  },
                  b: {
                    backgroundColor: 'transparent',
                    color: '#000'
                  }
                },
                padding: [120, 0, 0, 60]
              }
            },
            {
              type: 'min',
              name: '最小值',
              symbol: 'none',
              lineStyle: {
                //标注线样式
                normal: {
                  type: 'dotted',
                  color: '#000' //标注线颜色
                }
              },
              label: {
                show: true,
                position: 'end',
                formatter: '{a|下限(UCL) : }{b|{c}}',
                rich: {
                  a: {
                    backgroundColor: 'transparent',
                    color: '#000'
                  },
                  b: {
                    backgroundColor: 'transparent',
                    color: '#000'
                  }
                },
                padding: [0, 0, 25, -80]
              }
            }
          ]
        }
      }
    ]
  }
}

运行后如下图所示,根据实际情况进行位置调整

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暮暮最后的倔强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值