search

Home  >  Q&A  >  body text

javascript - When there are too many characters in the legend of echarts, how to change it into an ellipsis?

I am now making an echarts pie chart, in which the legend is dynamically generated. Sometimes more than a dozen texts are sent to the background, and the style is ugly. Now I want to realize: when the text in a single legend exceeds 8 , automatically turns into an ellipsis of "..." (as shown in the picture below), please give me some advice.

过去多啦不再A梦过去多啦不再A梦2771 days ago741

reply all(3)I'll reply

  • 迷茫

    迷茫2017-05-19 10:21:29

    There is a formatter under the legend configuration item

    formatter: function (name) {
        return (name.length > 8 ? (name.slice(0,8)+"...") : name ); 
    }

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:21:29

    Make a judgment and then use string concatenation.

    if(name.length>8){
        name=name.slice(0,8)+"..."
    }

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:21:29

    If the annotation is not displayed on the pie chart, it can be intercepted after the data is transmitted from the background.
    Or just format it.

    formatter: function(name){
                return name.length>8?name.substr(0,7)+"...":name;
            }

    reply
    0
  • Cancelreply