echarts 双Y轴,最大值,

文章描述了一个使用ECharts库创建的收入利润曲线图表,展示了用户数与利润、收入之间的关系,通过yAxisIndex控制了不同系列数据在两个y轴上的展示位置,并设置了自适应的标签位置策略。

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

this.value = [
        [0, 0],
        [10, 788],
        [30, 3663],
        [50, 7038],
        [100, 16776]
      ];
this.value2 = [
        [0, 0],
        [10, 4500],
        [30, 13500],
        [50, 22500],
        [100, 45000]
      ];
const showLabel = 7038;
const showLabel2 = 22500;
option = {
  title: {
    text: '收入利润曲线(万元)'
  },
  tooltip: {
    trigger: 'axis'
  },
  xAxis: {
    name: '用户数(万)',
    nameLocation: 'middle'
  },
  yAxis: [{
                type: "value",
                //name: "数量",
                // interval: 10,
                show: true,
                min: 0,
                max: 60000,
                nameTextStyle: {
                  color: "#000"
                },
                axisLabel: {
                  textStyle: {
                    color: "#000"
                  }
                },
              },

              {
                type: "value",
                //name: "挂起后通过比例",
                position: "right",
                min: 0,
                max: 18000,
                show: true
              }],
  series: [
    {
      itemStyle: { normal: { label: { show: true } } },

      name: '利润',
      showAllSymbol: true,
      data: this.value.map(item => {
       return {
         value: item,
         label: {
           show: true,
           position: item[1] < showLabel ? 'bottom' : 'top'
         }
       }
     }),
      type: 'line',
      yAxisIndex: 1,
      smooth: true
    },
    {
      itemStyle: { normal: { label: { show: true } } },
      name: '收入',
      showAllSymbol: true,
      data: this.value2.map(item => {
       return {
         value: item,
         label: {
           show: true,
           position: item[1] < showLabel2 ? 'top' : 'bottom'
         }
       }
     }),
      type: 'line',
      smooth: true
    }
  ]
};

在这里插入图片描述

Axis的yAxisIndex属性 echarts配置多个y轴的时候,需要加上: yAxisIndex;

series数据中,yAxisIndex值为0对应的y轴是yAxis对应的第一条y轴;

series数据中,yAxisIndex值为1 对应的y轴是yAxis对应的第二条y轴;

const showLabel = 7038; position: item[1] < showLabel2 ? ‘top’ : ‘bottom’ :当折线图有交点时,数值小于7038,标题在顶部。数值大于7038标题在底部;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值