/*
 * @Author: gj
 * @Date: 2020-07-01 18:13:55
 * @Description: echarts文字较多时换行展示
 * @FilePath: \chart-component\customjs\echarts\newlineEcharts.js
 */ 
var newlineEcharts = function newline(option, number, axis){
  var axisLabelConfig = option[axis]['axisLabel'] ? option[axis]['axisLabel'] : {};
  option[axis]['axisLabel']={
    ...axisLabelConfig,
    interval: 0,
    formatter: function(params){
      var newParamsName = "";
      var paramsNameNumber = params.length;
      var provideNumber = number;
      var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
      if (paramsNameNumber > provideNumber) {
        for (var p = 0; p < rowNumber; p++) {
          var tempStr = "";
          var start = p * provideNumber;
          var end = start + provideNumber;
          if (p == rowNumber - 1) {
            tempStr = params.substring(start, paramsNameNumber);
          } else {
            tempStr = params.substring(start, end) + "\n";
          }
          newParamsName += tempStr;
        }
        } else {
          newParamsName = params;
        }
        return newParamsName
    }
  }
  return option;
}
export default newlineEcharts;