MPAndroidChart
MPAndroidChart copied to clipboard
Axis multiline labels
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"+"%";
}
});
Maybe it will be better to use StaticLayout for multiline text instead of splitting by '\n'?
This modification would be useful. hope @PhilJay or someone else will have a look :)
The texts are not center aligned.
Here are my updates to your PR.
In Utils.java#drawXMultiLineText()
- Change
paint.setTextAlign(Paint.Align.LEFT);
topaint.setTextAlign(Paint.Align.CENTER);
- Change
drawOffsetX += x;
todrawOffsetX += 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.
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 :)
How can I edit this file if the Util.java is read-only file? I need helppp :(
@joyceHong0524 You need to clone, edit and build the project yourself
I also tried setMultiLineLabel(true) but it doesn't work. For example?
+1 interested in this. Please add!