Echarts legend overlap (reprinted), echartslegend
Solution:
1. Adjust the grid. top value in option to avoid overlap. (You can set custom values or define a calculation formula)
2. The document specifies the special string ''(Null String) or '\ n' (line feed string) used for line feed of the legend .]
Source: http://blog.csdn.net/doleria/article/details/52503763
The content is as follows:
Github address: Data Visualization
Certificate ---------------------------------------------------------------------------------------------------------------------------------------
When there are too many Echarts report headers, although Echarts will be adaptive, the legend text may be too long, and the legends and chart lines will inevitably overlap. As shown in:
Refer to this article and the official Echarts documentation to come up with the following solutions:
1. The document specifies the special string ''(Null String) or '\ n' (line feed string) used for line feed of the legend .]
2. After wrapping, the grid. top value in option can be dynamically adjusted to avoid overlap. (A formula is defined)
To solve this problem, I used PHP to write a class for customizing Echarts. The following section is related to the legend adjustment, which is for reference only:
[Php]View plain copy
- <? Php
- /**
- * Created by PhpStorm.
- * User: liuyuning
- * Date: 2016/8/9
- * Time: 18: 59
- */
- Class Ep_CustomizeEcharts {
- Const LINE_NUM_EACH_ROW = 3; // number of lines displayed in each line in the legend;
- Const DEFAULT_LINE_NUM = 6; // use the default number of lines with the default grid. top value;
- Const DEFAULT_GRID_TOP_PECENTAGE = 18; // default grid. top percentage (integer );
- Const DELTA_GRID_TOP_PECENTAGE = 9; // grid. top percentage increment when the default number of lines is exceeded (integer );
- Const MAX_GRID_TOP_PECENTAGE = 50; // maximum grid. top percentage (integer );
- /**
- * Adjust the legend display style
- * @ Params the legend to be adjusted in array
- * @ Return array
- */
- Public function adjustLegend ($ beforeLegend ){
- // When there are too many legends, the Echarts document specifies the special string ''(Null String) or '\ n' (line feed string) for the line feed of the legend .]
- $ 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;
- }
- /**
- * Set the grid. top value.
- * @ Params the legend to be adjusted in array
- * @ Return string
- */
- Public function setGridTop ($ arrLegend ){
- $ Len = count ($ arrLegend );
- // If there are too many legends, you must adjust the grid. top value in option to avoid overlap.
- $ 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;
- }
- }
Shows the adjusted effect:
Github address: Data Visualization