vue+echarts折线图使用两条Y轴

本文介绍了如何在Vue.js项目中结合Echarts库创建一个具有两条Y轴的折线图。通过在Echarts配置的yAxis选项中设定两个独立的轴,并在series中为每个数据系列指定对应的yAxisIndex,成功实现了效果。

效果实现:

 在yAxis设置中:

yAxis: [
            {
              type: "value",
              splitLine:false,
              position: 'left',//控制Y轴的方向
              alignTicks: true,
              //  改变Y轴颜色
              axisLine:{
                  lineStyle:{
                      color:'#20E3F1',
                  }
              },                         
              //  改变Y轴字体颜色和大小  
              axisLabel: {
                  textStyle: {
                      color: 'rgba(206, 223, 255, 0.6)',
                      fontSize:'9'
                  },
                  formatter: '{value}'
              },   
            },
            {
              type: "value",
              splitLine:false,
              position: 'right',
              alignTicks: true,
              //  改变Y轴颜色
              axisLine:{
                  lineStyle:{
                      color:'#20E3F1',
                  }
              },                         
              //  改变Y轴字体颜色和大小  
              axisLabel: {
                  textStyle: {
                      color: 'rgba(206, 223, 255, 0.6)',
                      fontSize:'9'
                  },
                  formatter: '{value}'
              },   
            },
          ],

在series里面增加yAxisIndex: 1,

series: [
            {
              name: "用餐人数",
              type: "line",
              itemStyle: {
                  color: '#FBC900'
              },
              areaStyle: {
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                          offset: 0,
                          color: 'rgba(251, 201, 0, 0.3)'
                      },
                      {
                          offset: 1,
                          color: 'rgba(251, 201, 0, 0.2)'
                      }
                  ])
              },
              emphasis: {
                focus: "series",
              },
              data: yPeopleData,
            },
            {
              name: "交易额",
              type: "line",
              itemStyle: {
                  color: '#07A9E8'
              },
              yAxisIndex: 1,//使用的事配置的第二天Y轴
              areaStyle: {
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                          offset: 0,
                          color: 'rgba(7, 169, 232, 0.3)'
                      },
                      {
                          offset: 1,
                          color: 'rgba(7, 169, 232, 0.2)'
                      }
                  ])
              },
              emphasis: {
                focus: "series",
              },
              data: yMoneyData,
            }
          ],

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值