Echarts legend overlaps, echartslegend

Source: Internet
Author: User

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
  1. <? Php
  2. /**
  3. * Created by PhpStorm.
  4. * User: liuyuning
  5. * Date: 2016/8/9
  6. * Time: 18: 59
  7. */
  8. Class Ep_CustomizeEcharts {
  9. Const LINE_NUM_EACH_ROW = 3; // number of lines displayed in each line in the legend;
  10. Const DEFAULT_LINE_NUM = 6; // use the default number of lines with the default grid. top value;
  11. Const DEFAULT_GRID_TOP_PECENTAGE = 18; // default grid. top percentage (integer );
  12. Const DELTA_GRID_TOP_PECENTAGE = 9; // grid. top percentage increment when the default number of lines is exceeded (integer );
  13. Const MAX_GRID_TOP_PECENTAGE = 50; // maximum grid. top percentage (integer );
  14. /**
  15. * Adjust the legend display style
  16. * @ Params the legend to be adjusted in array
  17. * @ Return array
  18. */
  19. Public function adjustLegend ($ beforeLegend ){
  20. // 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 .]
  21. $ AfterLegend = array ();
  22. $ Index = 0;
  23. $ Len = count ($ beforeLegend );
  24. For ($ I = 0; $ I <$ len; $ I ++ ){
  25. If ($ index + 1) % (self: LINE_NUM_EACH_ROW + 1) === 0 ){
  26. $ AfterLegend [$ index] = '';
  27. $ Index ++;
  28. $ AfterLegend [$ index] = $ beforeLegend [$ I];
  29. } Else {
  30. $ AfterLegend [$ index] = $ beforeLegend [$ I];
  31. }
  32. $ Index ++;
  33. }
  34. Return $ afterLegend;
  35. }
  36. /**
  37. * Set the grid. top value.
  38. * @ Params the legend to be adjusted in array
  39. * @ Return string
  40. */
  41. Public function setGridTop ($ arrLegend ){
  42. $ Len = count ($ arrLegend );
  43. // If there are too many legends, you must adjust the grid. top value in option to avoid overlap.
  44. $ TopInt = $ len> self: DEFAULT_LINE_NUM?
  45. Self: DEFAULT_GRID_TOP_PECENTAGE + self: DELTA_GRID_TOP_PECENTAGE
  46. * (Ceil ($ len-self: DEFAULT_LINE_NUM)/self: LINE_NUM_EACH_ROW ))
  47. : Self: DEFAULT_GRID_TOP_PECENTAGE;
  48. If ($ topInt> = self: MAX_GRID_TOP_PECENTAGE ){
  49. $ TopInt = self: MAX_GRID_TOP_PECENTAGE;
  50. }
  51. $ GridTop = "$ topInt % ";
  52. Return $ gridTop;
  53. }
  54. }



 

Shows the adjusted effect:

Github address: Data Visualization

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.