<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          echarts自定義圖例組件

          2021-7-15    前端達人

          效果圖如下
          在這里插入圖片描述

          //圖例組件
                  legend: {
                    top: 'center',
                    right: 30,
                    data: [],
                    width: "auto",
                    itemWidth: 10,  // 小方塊尺寸
                    itemHeight: 10,
                    textStyle: {
                      color:'#90CCFF',
                      lineHeight:20,
                      // 通過rich自定義尺寸,加寬度使百分比及數值各自對齊
                      rich:{
                        a:{
                          width:100,
                          align:'left'
                        },
                        b:{
                          width:40,
                          align:'right'
                        }
                      }
                    },
                    orient: 'vertical',      // 豎向排列
                    // 通過formatte自定義格式
                    // 因為formatter的參數里只有name一個參數,所以需要通過獲取的數據匹配顯示
                    // 這里的optionData是獲取到的數據,格式為
                    // optionData:[
                    //  { value: 47.01, name: "水果" },
                    //  { value: 31.67, name: "蔬菜" },
                    //  { value: 12.51, name: "禽畜" },
                    //  { value: 8.24, name: "禽蛋" },
                    //  { value: 7.27, name: "水產品" },
                    //  { value: 6.32, name: "其他" }
                    // ],
                    formatter: (name) => {
                      var total = 0;
                      var tarValue;
                      this.optionData.forEach((item,i) => {
                        total += Number(item.value)
                        if (item.name == name) {
                          tarValue = Number(item.value ? item.value : 0)
                        }
                      });
                      var percent = ((tarValue / total) * 100).toFixed(2)
                      let arr = [
                        '{a|'+name+" : "+percent+'%}'+'{b|'+tarValue+'張}'
                      ]
                      return arr
                    }
                  }  
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51

          自定義legend的方式就是這樣,遇到格式不同的可以參考上面的方式自定義

          單獨定義echarts中每個圖例的樣式,自定義圖例的點擊方法

           

          //用不同樣式的圖例用數組寫對應圖例的樣式
                          legend:[{
                              top: "15%",
                              right: "24%",
                              textStyle: {
                                  color: "#3BAEFE",
                                  fontSize: 14,
                                  fontFamily: "微軟雅黑"
                              },
                              itemWidth: 27,
                              itemHeight: 16,
                              data:[{
                                  name: "農藥",
                                  icon: "circle"
                              },{
                                  name: "LOL",
                                  icon: "rect"
                              }]
                          },{
                              top: "15%",
                              right: "15%",
                              textStyle: {
                                  color: "#3BAEFE",
                                  fontSize: 14,
                                  fontFamily: "微軟雅黑"
                              },
                              itemWidth: 33,
                              itemHeight: 16,
                              data:[{
                                  name: "農藥+LOL",
                                  icon: "image:///soyking/static/image/echarts/merge.png"  //引用自定義的圖片
                              }]
                          },{
                              top: "15%",
                              right: "15%",
                              textStyle: {
                                  color: "#3BAEFE",
                                  fontSize: 14,
                                  fontFamily: "微軟雅黑"
                              },
                              data:["\n","\n","\n","農藥占比","LOL占比"]
                          }],

           

          結果:

           

          自定義圖例的方法 (點擊圖例,顯示圖例的選中結果) 

          var bar = echarts.init(document.getElementById("barDiv"));

          //自定義圖例的方法
                      bar.on("legendselectchanged",function(obj){
                          //獲取圖例選擇的結果
                          var selected = obj.selected;
                          for(var i in selected){
                              alert(selected[i]);
                          }
                      });


          藍藍設計建立了UI設計分享群,每天會分享國內外的一些優秀設計,如果有興趣的話,可以進入一起成長學習,請掃碼藍小助,報下信息,藍小助會請您入群。歡迎您加入噢~~希望得到建議咨詢、商務合作,也請與我們聯系。

          截屏2021-05-13 上午11.41.03.png


          分享此文一切功德,皆悉回向給文章原作者及眾讀者.

          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務



          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合