Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

MPAndroidChart Label entries customization

$
0
0

enter image description hereIs MPAndroidChart support to customize the label entries? I'm trying to set the TARGET AND ACTUAL label entries rotate to its normal degree or 0f and make the text (Green highlight) stay to its 70 degrees or 70f.

I have successfully rotated the label entries but when i try to customize it, its not really working. I tried to research but i can't find any related to it.

I use a class renderer for this rotation:

class CustomBarChartRendererA1(chart: BarChart, animator: ChartAnimator, viewPortHandler: ViewPortHandler) : BarChartRenderer(chart, animator, viewPortHandler) {    override fun drawValue(canvas: Canvas?, valueText: String?, x: Float, y: Float, color: Int) {        mValuePaint.color = color        canvas?.save()        if (valueText != null && (valueText == "TARGET" || valueText == "ACTUAL")) {            // Rotate text for "TARGET" and "ACTUAL"            canvas?.rotate(0f, x, y)            val xOffset = 0f // adjust position             val yOffset = 0f // adjust position             canvas?.drawText(valueText, x + xOffset, y + yOffset, mValuePaint)            // Rotate back to the original orientation            canvas?.rotate(0f, 0f, 0f)        } else if (valueText != null && valueText == "MODEL") {            // Rotate text for "MODEL"            canvas?.rotate(270f, x, y)            val xOffset = 70f            if (valueText != null) {                canvas?.drawText(valueText, x + xOffset, y, mValuePaint)            }            // Restore the canvas to the original state            canvas?.restore()        }    }}

and call this renderer:

val customRenderer = CustomBarChartRendererA1(                    barChartView,                    barChartView.animator,                    barChartView.viewPortHandler                )                valuesModel?.let {                    List(it.size) { index ->                        BarEntry(index.toFloat() + 1 + uniqueEntries.size.toFloat() * 0.2f, 1f)                    }                }

Viewing all articles
Browse latest Browse all 11661

Trending Articles