echarts中双y轴刻度线对齐的问题

本文探讨了在Echarts中处理双Y轴刻度线对齐的问题,关键在于设置splitNumber保持段数一致,确保max值大于等于数据最大值,并通过interval强制设定坐标轴分割间隔,以实现刻度线的比例平衡,从而达到对齐效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • splitNumber设置分割的段数,必须一致
  • 设置的max一定是大于或等于数据最大值,计算找出数据中最大值向上取整
  • interval强制设置坐标轴分割间隔,控制两边刻度比例一样才能保持刻度线对齐
// consumption 和 throughputList 是API返回的数据
yAxis: [{
        // name: '左轴',
        type: 'value',
        min: 0,
        splitNumber: 5,
        interval: Math.ceil(Math.ceil(Math.max(...consumption)) / 5),
        max:Math.ceil(Math.ceil(Math.max(...consumption)) / 5) * 5,
        splitLine: {
          lineStyle: {
            color: '#ccc'
          }
        }
      },
      {
        // name: '右轴',
        type: 'value',
        min: 0,
        splitNumber: 5,
        interval: Math.ceil(Math.ceil(Math.max(...throughputList)) / 5),
        max: Math.ceil(Math.ceil(Math.max(...throughputList)) / 5) * 5,
        splitLine: {
          lineStyle: {
            color: '#ccc'
          }
        },
        axisLabel: {
          textStyle: {
            color: '#000'
          }
        }
      }
    ],

如图所示
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值