Skip to content

Axis multiline labels#3190

Open
fabriziogueli wants to merge 3 commits intoPhilJay:masterfrom
fabriziogueli:axis_multiline_labels
Open

Axis multiline labels#3190
fabriziogueli wants to merge 3 commits intoPhilJay:masterfrom
fabriziogueli:axis_multiline_labels

Conversation

@fabriziogueli
Copy link
Copy Markdown

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"+"%";
            }
        });

@shamilovstas
Copy link
Copy Markdown

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

@ClemMahe
Copy link
Copy Markdown

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

@dhagz
Copy link
Copy Markdown

dhagz commented Jul 14, 2017

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.

@felislynx-silae
Copy link
Copy Markdown

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 :)

masako-yamada added a commit to masako-yamada/MPAndroidChart that referenced this pull request Apr 4, 2018
Based on fabriziogueli’s change:
PhilJay#3190
@joyceHong0524
Copy link
Copy Markdown

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

@vicmpen
Copy link
Copy Markdown

vicmpen commented Apr 29, 2020

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

@eunyeong1328
Copy link
Copy Markdown

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

@saldous
Copy link
Copy Markdown

saldous commented Apr 29, 2022

+1 interested in this. Please add!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.