Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart set highlight color

Just wondering if anyone has figured out how to set the highlight color for a bar chart in MPAndroidChart? Currently it's like a dark black (somewhat transparent) overlay. I would like to make it a white (somewhat transparent) overlay, and maybe even a gradient. Kind of like this:

enter image description here

like image 429
Chase Roberts Avatar asked Feb 09 '23 14:02

Chase Roberts


1 Answers

The BarDataSet extends BarLineScatterCandleBubbleDataSet which has a setHighLightColor method:

/**
 * Sets the color that is used for drawing the highlight indicators. Dont
 * forget to resolve the color using getResources().getColor(...) or
 * Color.rgb(...).
 * 
 * @param color
 */
public void setHighLightColor(int color) {
    mHighLightColor = color;
}

The BarDataSet also has a setHighLightAlpha method:

/**
 * Set the alpha value (transparency) that is used for drawing the highlight
 * indicator bar. min = 0 (fully transparent), max = 255 (fully opaque)
 * 
 * @param alpha
 */
public void setHighLightAlpha(int alpha) {
    mHighLightAlpha = alpha;
}

Neither of these methods would support a gradient but you can change the appearance of the highlight.

If you are looking to implement the gradient highlighting you can probably extend the BarChartRenderer and override the drawHighlighted(Canvas c, Highlight[] indices) and apply it to your chart via the setRenderer method (I haven't tried this personally).

like image 83
Cory Charlton Avatar answered Mar 08 '23 07:03

Cory Charlton