Chase Roberts
Chase Roberts

Reputation: 9376

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

Upvotes: 4

Views: 6670

Answers (1)

Cory Charlton
Cory Charlton

Reputation: 8938

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).

Upvotes: 8

Related Questions