Skip to content

Commit 6ebf3fa

Browse files
committed
Added highlightColor parameter for pie charts
ChartsOrg/Charts#2961
1 parent 95027fa commit 6ebf3fa

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/data/PieDataSet.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
55
import com.github.mikephil.charting.utils.Utils;
6+
import android.support.annotation.Nullable;
67

78
import java.util.ArrayList;
89
import java.util.List;
@@ -29,6 +30,7 @@ public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {
2930
private float mValueLinePart1Length = 0.3f;
3031
private float mValueLinePart2Length = 0.4f;
3132
private boolean mValueLineVariableLength = true;
33+
private Integer mHighlightColor = null;
3234

3335
public PieDataSet(List<PieEntry> yVals, String label) {
3436
super(yVals, label);
@@ -218,6 +220,21 @@ public void setValueLineVariableLength(boolean valueLineVariableLength) {
218220
this.mValueLineVariableLength = valueLineVariableLength;
219221
}
220222

223+
/** Gets the color for the highlighted sector */
224+
@Override
225+
@Nullable
226+
public Integer getHighlightColor()
227+
{
228+
return mHighlightColor;
229+
}
230+
231+
/** Sets the color for the highlighted sector (null for using entry color) */
232+
public void setHighlightColor(@Nullable Integer color)
233+
{
234+
this.mHighlightColor = color;
235+
}
236+
237+
221238
public enum ValuePosition {
222239
INSIDE_SLICE,
223240
OUTSIDE_SLICE

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IPieDataSet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.mikephil.charting.interfaces.datasets;
22

3+
import android.support.annotation.Nullable;
4+
35
import com.github.mikephil.charting.data.PieDataSet;
46
import com.github.mikephil.charting.data.PieEntry;
57

@@ -70,5 +72,11 @@ public interface IPieDataSet extends IDataSet<PieEntry> {
7072
* */
7173
boolean isValueLineVariableLength();
7274

75+
/**
76+
* Gets the color for the highlighted sector
77+
* */
78+
@Nullable
79+
Integer getHighlightColor();
80+
7381
}
7482

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,10 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
857857

858858
final boolean accountForSliceSpacing = sliceSpace > 0.f && sliceAngle <= 180.f;
859859

860-
mRenderPaint.setColor(set.getColor(index));
860+
Integer highlightColor = set.getHighlightColor();
861+
if (highlightColor == null)
862+
highlightColor = set.getColor(index);
863+
mRenderPaint.setColor(highlightColor);
861864

862865
final float sliceSpaceAngleOuter = visibleAngleCount == 1 ?
863866
0.f :

0 commit comments

Comments
 (0)