1. 程式人生 > 其它 >echarts 圖例元件如何分行

echarts 圖例元件如何分行

技術標籤:視覺化大屏echarts

legend: [
{
  left:'80',
  data: ['郵件', 'QQ檔案', '微信', '檔案傳輸'],
  textStyle: {
    color: '#fff',
  }
},
{
  top:'20',
  left:'80',
  data:['木馬','漏洞','惡意檔案','其他'],
  textStyle: {
    color: '#fff',
  }
}
],

把圖裡元件用陣列分成2組 其他正常

通過left、top、right、bottom 使其佈局
在這裡插入圖片描述

把圖裡元件全部對齊

通過textStyleformatter

搭配richwidth 實現對齊
原理:通過富文字設定固定的寬度

 legend: [
   {
     left:'30',
     data: ['郵件', 'QQ檔案', '微信', '檔案傳輸'],
     formatter: '{a|{name}}',
     textStyle: {
       color: '#fff',
       rich:{
         a:{
           width: 60,
           fontSize: 12
         },
       }
     }
   },
   {
     top:'25'
, left:'30', formatter: '{a|{name}}', data:['木馬','漏洞','惡意檔案','其他'], textStyle: { color: '#fff', rich:{ a:{ width: 60, fontSize: 12 }, } } } ],

在這裡插入圖片描述