MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Axis multiline labels

Open fabriziogueli opened this issue 7 years ago • 8 comments

This PR allow multiline labels on the xAxis using '\n'

Example :

  XAxis xAxis = mChart.getXAxis();
  xAxis.setMultiLineLabel(true);


  xAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
           public String getFormattedValue(float value, AxisBase axis) {
                return value+"\n"+"%";
            }
        });

fabriziogueli avatar Jun 16 '17 14:06 fabriziogueli

Maybe it will be better to use StaticLayout for multiline text instead of splitting by '\n'?

shamilovstas avatar Jul 05 '17 11:07 shamilovstas

This modification would be useful. hope @PhilJay or someone else will have a look :)

ClemMahe avatar Jul 13 '17 11:07 ClemMahe

The texts are not center aligned. Here are my updates to your PR. In Utils.java#drawXMultiLineText()

  • Change paint.setTextAlign(Paint.Align.LEFT); to paint.setTextAlign(Paint.Align.CENTER);
  • Change drawOffsetX += x; to drawOffsetX += x + (mDrawTextRectBuffer.width() / 2.0f);

These changes are not tested if the angleDegrees != 0.f

The user should also add myChart.setExtraBottomOffset(20); or any number to accomodate the new line.

dhagz avatar Jul 14 '17 16:07 dhagz

It is very important feature! I hope someone will look at this. If you have problem with alignment, use static layout. From my experience it is much easier than calculating manually :)

felislynx-silae avatar Jul 30 '17 08:07 felislynx-silae

How can I edit this file if the Util.java is read-only file? I need helppp :(

joyceHong0524 avatar Feb 15 '20 18:02 joyceHong0524

@joyceHong0524 You need to clone, edit and build the project yourself

vicmpen avatar Apr 29 '20 10:04 vicmpen

I also tried setMultiLineLabel(true) but it doesn't work. For example?

eunyeong1328 avatar Jul 02 '21 04:07 eunyeong1328

+1 interested in this. Please add!

saldous avatar Apr 29 '22 21:04 saldous