In MPAndroidChart Library, How to wrap X Axis Labels to two lines when long?

前端 未结 6 753
误落风尘
误落风尘 2020-12-05 07:32

I am trying to show X axis label to go to 2 lines when they are long. How to achieve this in LineChart? See screenshot below. I want time to go to second line instead of sta

6条回答
  •  萌比男神i
    2020-12-05 08:10

    Improved version of @Guillaume Jounel's answer to support multiple newlines, as well as strings w/o a newline.

        @Override
        protected void drawLabel(Canvas c, String formattedLabel, float x, float y,
                                     MPPointF anchor, float angleDegrees) {
        String line[] = formattedLabel.split("\n");
        Utils.drawXAxisValue(c, line[0], x, y, mAxisLabelPaint, anchor, angleDegrees);
            for (int i = 1; i < line.length; i++) { // we've already processed 1st line
                 Utils.drawXAxisValue(c, line[i], x, y + mAxisLabelPaint.getTextSize() * i,
                     mAxisLabelPaint, anchor, angleDegrees);
            }
        }
    

提交回复
热议问题