echarts XY轴label过长问题解决

    xAxis: {
          data: this.liveDataName,
          axisTick: {
            alignWithLabel: true,
          },
          axisLabel: {
            // color: 'red',
            fontSize: "11",
            interval: 0,
            // rotate: -30
            formatter: function (value) {
              var str = "";
              var num = 5; //每行显示字数 
              var valLength = value.length; //该项x轴字数  
              var rowNum = Math.ceil(valLength / num); // 行数  

              if (rowNum > 1) {
                for (var i = 0; i < rowNum; i++) {
                  var temp = "";
                  var start = i * num;
                  var end = start + num;

                  temp = value.substring(start, end) + "\n";
                  str += temp;
                }
                return str;
              } else {
                return value;
              }
            }
          },
          axisLine: {
            show: true,
          },
        },

原文http://events.jianshu.io/p/412500172201

你可能感兴趣的:(echarts XY轴label过长问题解决)