Is it possible to set different label color for y-axis label in mpandroidchart ? is possible how? any help appreciated.
Add below code of line
chart.getAxisLeft().setTextColor(ContextCompat.getColor(this, R.color.red)); // left y-axis
You can custom YAxisRenderer like this to achieve it.
Add it to your chart
chart.setRendererLeftYAxis(new MyYAxisLeftRenderer(chart.getViewPortHandler(),
chart.getAxisLeft(),chart.getTransformer(YAxis.AxisDependency.LEFT)));
public class MyYAxisLeftRenderer extends YAxisRenderer {
@Override
protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
final int to = mYAxis.isDrawTopYLabelEntryEnabled()
? mYAxis.mEntryCount
: (mYAxis.mEntryCount - 1);
// draw
for (int i = from; i < to; i++) {
String text = mYAxis.getFormattedLabel(i);
// change y label color here before drawing (i is an index of label)
mAxisLabelPaint.setColor();
c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With