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

前端 未结 6 782
误落风尘
误落风尘 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条回答
  •  难免孤独
    2020-12-05 08:00

    No need to offset x coordinate. And for multi-line scenario the code should be

    @Override
    protected void drawLabel(Canvas c, String formattedLabel, float x, float y, MPPointF anchor, float angleDegrees) {
        String lines[] = formattedLabel.split("\n");
        for (int i = 0; i < lines.length; i++) {
            float vOffset = i * mAxisLabelPaint.getTextSize();
            Utils.drawXAxisValue(c, lines[i], x, y + vOffset, mAxisLabelPaint, anchor, angleDegrees);
        }
    }
    

提交回复
热议问题