解决方案:
1. 调整option中的grid.top值才能避免重叠;(能够设置定制,也能够定义了一个计算公式)php
2. 文档注明【特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的换行。】git
转载来源:http://blog.csdn.net/doleria/article/details/52503763github
内容以下:spa
github地址:Data Visualization.net
---------------------------------------------------------------------------------------------------------------------------------------orm
当Echarts报表表头过多时,虽然Echarts会作自适应,可是因为图例文字可能过长等,图例与图表线条不免会重叠显示。以下图所示:
blog
参考这篇文章,以及Echarts的官方文档,得出如下解决方案:文档
1. 文档注明【特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的换行。】
2. 换行后动态调整option中的grid.top值才能避免重叠;(定义了一个计算公式)字符串
在解决这个问题时,用PHP写了个定制Echarts的类,其中与调整图例相关的部分以下,仅供参考:get
- <?php
-
- /**
- * Created by PhpStorm.
- * User: liuyuning
- * Date: 2016/8/9
- * Time: 18:59
- */
- class Ep_CustomizeEcharts {
-
- const LINE_NUM_EACH_ROW = 3; //图例中每行显示的线条数目;
- const DEFAULT_LINE_NUM = 6; //采用默认grid.top值的默认线条数目;
- const DEFAULT_GRID_TOP_PECENTAGE = 18; //默认的grid.top百分比(整数部分);
- const DELTA_GRID_TOP_PECENTAGE = 9; //超出默认线条数时的grid.top百分比增量(整数部分);
- const MAX_GRID_TOP_PECENTAGE = 50; //最大的grid.top百分比(整数部分);
-
-
- /**
- * 调整图例显示样式
- * @params array 须要调整的图例
- * @return array
- */
- public function adjustLegend ($beforeLegend) {
- // 图例太多时,Echarts文档注明【特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的换行。】
- $afterLegend = array();
- $index = 0;
- $len = count($beforeLegend);
- for ( $i = 0; $i < $len; $i++) {
- if (($index+1)%(self::LINE_NUM_EACH_ROW + 1) === 0) {
- $afterLegend[$index] = '';
- $index++;
- $afterLegend[$index] = $beforeLegend[$i];
- } else {
- $afterLegend[$index] = $beforeLegend[$i];
- }
- $index++;
- }
-
- return $afterLegend;
- }
-
- /**
- * 设置grid.top值
- * @params array 须要调整的图例
- * @return string
- */
- public function setGridTop($arrLegend) {
-
- $len = count($arrLegend);
-
- // 若是图例太多,须要调整option中的grid.top值才能避免重叠
- $topInt = $len > self::DEFAULT_LINE_NUM ?
- self::DEFAULT_GRID_TOP_PECENTAGE + self::DELTA_GRID_TOP_PECENTAGE
- * (Ceil(($len - self::DEFAULT_LINE_NUM)/self::LINE_NUM_EACH_ROW))
- : self::DEFAULT_GRID_TOP_PECENTAGE;
- if ($topInt >= self::MAX_GRID_TOP_PECENTAGE) {
- $topInt = self::MAX_GRID_TOP_PECENTAGE;
- }
- $gridTop = "$topInt%";
-
- return $gridTop;
- }
-
- }
调整好的效果以下图所示:

github地址:Data Visualization