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

效果实现:

 在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,
            }
          ],

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现 Vue+Echarts 柱状图的 y 从大到小排序,可以使用以下步骤: 1. 在 Echarts 的配置项中,设置 y 的 type 为 "value"。 2. 在 y 线样式中,设置 axisLabel 的 formatter 属性,使用一个回调函数来对 y 的标签进行排序。 3. 在回调函数中,使用 sort() 方法对 y 数据进行排序,然后返回排序后的标签数组。 下面是一个示例代码: ``` <template> <div id="chart" style="width: 600px;height:400px;"></div> </template> <script> import * as echarts from 'echarts'; export default { data() { return { chartData: [ { name: 'A', value: 76 }, { name: 'B', value: 68 }, { name: 'C', value: 82 }, { name: 'D', value: 91 }, { name: 'E', value: 72 }, { name: 'F', value: 68 }, { name: 'G', value: 95 }, ], }; }, mounted() { this.initChart(); }, methods: { initChart() { const chart = echarts.init(document.getElementById('chart')); const yAxisData = this.chartData.map(item => item.name).sort((a, b) => { return this.chartData.find(item => item.name === b).value - this.chartData.find(item => item.name === a).value; }); const option = { xAxis: { type: 'category', data: this.chartData.map(item => item.name), }, yAxis: { type: 'value', axisLabel: { formatter: (value) => { return yAxisData[value]; }, }, }, series: [ { data: this.chartData.map(item => item.value), type: 'bar', }, ], }; chart.setOption(option); }, }, }; </script> ``` 在上面的示例代码中,使用了一个回调函数来对 y 的标签进行排序。首先使用 map() 方法将原始数据中的名称提取出来,然后使用 sort() 方法对名称进行排序。在 axisLabel 的 formatter 属性中,使用回调函数返回排序后的标签数组。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值