在 MPAndroidChart 中,如何将 X 轴标签分成两行?对使用任何修改过的库不感兴趣

In MPAndroidChart, how to split X axis label into two lines? Not interested in using any modified library

设置自定义 X 轴渲染器无助于在水平条形图上将 x 轴标签拆分为多行。

barChart.setXAxisRenderer(CustomXAxisRenderer(barChart.viewPortHandler, xAxis, barChart.getTransformer(yAxis.axisDependency)))

我对使用 MPAndroidChart 库的任何修改版本不感兴趣。

class CustomXAxisRenderer(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, trans: Transformer?) : XAxisRenderer(viewPortHandler, xAxis, trans) {
        override fun drawLabel(c: Canvas?, formattedLabel: String, x: Float, y: Float, anchor: MPPointF?, angleDegrees: Float) {
            val line: List<String> = formattedLabel.split("\n")
            Utils.drawXAxisValue(c, line[0], y, x, mAxisLabelPaint, anchor, angleDegrees)
            for (i in 1 until line.size) { // we've already processed 1st line
                Utils.drawXAxisValue(c, line[i], y, x + mAxisLabelPaint.textSize * i,
                    mAxisLabelPaint, anchor, angleDegrees)
            }
        }
    }

请告诉我任何解决方案。

   class CustomXAxisRenderer(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, trans: Transformer?, chart: HorizontalBarChart) : XAxisRendererHorizontalBarChart(viewPortHandler, xAxis, trans, chart) {
        override fun drawLabel(c: Canvas?, formattedLabel: String, x: Float, y: Float, anchor: MPPointF?, angleDegrees: Float) {
            val line: List<String> = formattedLabel.split("\n")
            Utils.drawXAxisValue(c, line[0], x, y, mAxisLabelPaint, anchor, angleDegrees)
            for (i in 1 until line.size) {
                Utils.drawXAxisValue(c, line[i], x, y + mAxisLabelPaint.textSize * i,
                    mAxisLabelPaint, anchor, angleDegrees)
            }
        }
    }

这就解决了上面的问题。