Menu

maxWidth for xAxis Lables

JGR22
2013-08-09
2013-08-20
  • JGR22

    JGR22 - 2013-08-09

    Hi,
    I'm having trouble in dealing with long label names in XAxis for Column Chart. Is there any way we could set 'maxWidth' of css for those labels and ellipse(...) if it overflows.

    Any help would be appreciated.

     
  • Cory Skowronek

    Cory Skowronek - 2013-08-12

    One way to do this without using CSS would be to implement a custom formatter for your X-Axis Labels. Note that this specific code will simply truncate the label and not add any ellipsis to the end.

    
    chart.getXAxis()
        .setLabels(new XAxisLabels()
            .setFormatter(new AxisLabelsFormatter() {
                public String format(AxisLabelsData axisLabelsData) {
                    // If the length of the label is greater than three, only show the first three characters.
                    return axisLabelsData.getValueAsString().length() > 3 ? axisLabelsData.getValueAsString().substring(0, 3) : axisLabelsData.getValueAsString();
                }
            })
        )
    ;
    

    If you want to add the ellipsis to show that the label has been shortened, you can change the return statement to something like:

    
    return axisLabelsData.getValueAsString().length() > 3 ? axisLabelsData.getValueAsString().substring(0, 3) + "..." : axisLabelsData.getValueAsString();
    
     

    Last edit: Cory Skowronek 2013-08-13
  • JGR22

    JGR22 - 2013-08-20

    Thanks alot for your response. that fix worked :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.