MPAndroidChart: rotate X-Axis marks 90 degrees in BarChart

My xAxes text from BarChart from MPAndroidChart is too long. How can I rotate the xAxes label 90 degrees?

+4
source share
3 answers

Now it is possible in the library version 2.1.6

try it

XAxis xAxis=barChart.getXAxis(); xAxis.setLabelRotationAngle(-45); 
+16
source

you can hide the xAxis label and place the custom text view Vertical. Here is the code for viewing vertical text.

 public class VerticalTextView extends TextView { final boolean topDown; public VerticalTextView(Context context, AttributeSet attrs) { super(context, attrs); final int gravity = getGravity(); if (Gravity.isVertical(gravity) && (gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) { setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP); topDown = false; } else topDown = true; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(heightMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); } @Override protected void onDraw(Canvas canvas) { TextPaint textPaint = getPaint(); textPaint.setColor(getCurrentTextColor()); textPaint.drawableState = getDrawableState(); canvas.save(); if (topDown) { canvas.translate(getWidth(), 0); canvas.rotate(90); } else { canvas.translate(0, getHeight()); canvas.rotate(-90); } canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop()); getLayout().draw(canvas); canvas.restore(); } 

}

+1
source

It's simple, try this ...

 XAxis xAxis = barChart.getXAxis(); xAxis.setLabelRotationAngle(90); 
+1
source

All Articles