• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

EChartslegend分两行显示

武飞扬头像
小朱同学️
帮助1

  1. data中定义需要用到的字段

  1.  
    data() {
  2.  
    return {
  3.  
    legendData: [],//原始数组
  4.  
    oneData: [],//第一行
  5.  
    twoData: [],//第二行
  6.  
    }
  7.  
    },
  1. 将数组分为两个相等的部分

使用length/2和Math.ceil()方法找到数组的中间索引

使用中间索引和Array.splice()或者Array.slice()方法获得数组等分的部分

Math.ceil() 函数返回大于或等于一个给定数字的最小整数。

有时我们并不希望改变原始数组,这个可以配合 Array.slice() 来解决这个问题:

  1.  
    const middleIndex = Math.ceil(this.legendData.length / 2) //获取数组中间下标
  2.  
    this.oneData = this.legendData.slice(0, middleIndex)
  3.  
    this.twoData = this.legendData.slice(-middleIndex)

会有重复的可能,建议加一步去重操作

  1.  
    let list = this.twoData.filter(items => {
  2.  
    if (!this.oneData.includes(items)) return items
  3.  
    })
  4.  
    this.twoData = list

3.设置ECharts legend属性

  1.  
    legend: [
  2.  
    {
  3.  
    data: this.oneData,
  4.  
    // icon: 'roundRect',
  5.  
    x: 'center',
  6.  
    y: '2%',
  7.  
    textStyle: {
  8.  
    color: '#B2D9FF',
  9.  
    fontSize: 14
  10.  
    }
  11.  
    },
  12.  
    {
  13.  
    data: this.twoData,
  14.  
    // icon: 'roundRect',
  15.  
    x: 'center',
  16.  
    y: '6.5%',
  17.  
    textStyle: {
  18.  
    color: '#B2D9FF',
  19.  
    fontSize: 14
  20.  
    }
  21.  
    }
  22.  
    ],
学新通

显示效果

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfkcehf
系列文章
更多 icon
同类精品
更多 icon
继续加载