1

I have the next chart:

enter image description here

Is there any way to do word wrap for label description ? I was trying to add '\n' symbol but it's not working for me.

kkost
  • 3,640
  • 5
  • 41
  • 72
  • Probably make the screen in landscape mode. Which looks much better. Obviously this is not the answer for your question. – Sreehari Jul 18 '16 at 11:25
  • 1
    See https://stackoverflow.com/questions/32509174/in-mpandroidchart-library-how-to-wrap-x-axis-labels-to-two-lines-when-long – JFreeman Feb 05 '19 at 07:41

1 Answers1

1

Maybe try a custom XAxisValueFormatter:

public class MyCustomXAxisValueFormatter implements XAxisValueFormatter {

    @Override
    public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
        if(original.length() > 10)
        {
            original = original.substring(0, 6) + "\n" + original.substring(6, original.length());
        }
        return ...;
    }
}

Then apply it to your X-axis:

XAxis xAxis = chart.getXAxis();

xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
Harsh Pandey
  • 831
  • 7
  • 12
  • Hi, thanks for you reply, but it's not working for me. Custom formatter successfully updated string but it is still all in one line. Which version of library do you using ? Because me - MPAndroidChart:v2.2.5 – kkost Jul 18 '16 at 15:59
  • I'm not using the library at all right now. Although, I used v2.0. something in one of my projects. If this doesn't help you, then I am not sure what to do. Also, this might be a [known issue](https://github.com/PhilJay/MPAndroidChart/issues/377). – Harsh Pandey Jul 18 '16 at 16:06