diff --git a/.idea/runConfigurations/MPChartExample.xml b/.idea/runConfigurations/MPChartExample.xml
index e6bcf50331..7fd26b4e40 100644
--- a/.idea/runConfigurations/MPChartExample.xml
+++ b/.idea/runConfigurations/MPChartExample.xml
@@ -1,10 +1,13 @@
-
+
+
+
+
@@ -12,9 +15,8 @@
+
-
-
@@ -42,11 +44,18 @@
+
+
+
-
+
+
+
+
+
\ No newline at end of file
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
index 883eb7dfc1..2b2947ffba 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
@@ -29,6 +29,7 @@
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
+import java.util.List;
public class RadarChartActivity extends DemoBase {
@@ -147,6 +148,13 @@ private void setData() {
data.setValueTextColor(Color.WHITE);
chart.setData(data);
+ List colorList = new ArrayList<>();
+ colorList.add(Color.rgb(222, 166, 111));
+ colorList.add(Color.rgb(220, 206, 138));
+ colorList.add(Color.rgb(243, 255, 192));
+ colorList.add(Color.rgb(240, 255, 240));
+ colorList.add(Color.rgb(250, 255, 250));
+ chart.setLayerColorList(colorList);
chart.invalidate();
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java
index 8c0885395d..a0cb7b48bb 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java
@@ -16,6 +16,8 @@
import com.github.mikephil.charting.renderer.YAxisRendererRadarChart;
import com.github.mikephil.charting.utils.Utils;
+import java.util.List;
+
/**
* Implementation of the RadarChart, a "spidernet"-like chart. It works best
* when displaying 5-10 entries per DataSet.
@@ -64,6 +66,8 @@ public class RadarChart extends PieRadarChartBase {
*/
private YAxis mYAxis;
+ private List colorList;
+
protected YAxisRendererRadarChart mYAxisRenderer;
protected XAxisRendererRadarChart mXAxisRenderer;
@@ -179,6 +183,25 @@ public float getSliceAngle() {
return 360f / (float) mData.getMaxEntryCountSet().getEntryCount();
}
+
+ public void setLayerColorList(List colorList) {
+ if (colorList == null || colorList.size() == 0) {
+ return;
+ }
+ this.colorList = colorList;
+ }
+
+ public boolean isCustomLayerColorEnable() {
+ if (mData == null) {
+ return false;
+ }
+ return colorList != null && colorList.size() == getYAxis().mEntryCount;
+ }
+
+ public List getLayerColorList() {
+ return colorList;
+ }
+
@Override
public int getIndexForAngle(float angle) {
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
index dbf0e8f807..c9a911e6b7 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
@@ -28,6 +28,12 @@ public class RadarChartRenderer extends LineRadarRenderer {
protected Paint mWebPaint;
protected Paint mHighlightCirclePaint;
+ private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private Path previousPath = new Path();
+ private Path innerArea = new Path();
+ private Path temp = new Path();
+
+
public RadarChartRenderer(RadarChart chart, ChartAnimator animator,
ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
@@ -38,6 +44,10 @@ public RadarChartRenderer(RadarChart chart, ChartAnimator animator,
mHighlightPaint.setStrokeWidth(2f);
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
+ paint.setStyle(Paint.Style.FILL);
+ paint.setStrokeWidth(2f);
+ paint.setColor(Color.RED);
+
mWebPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mWebPaint.setStyle(Paint.Style.STROKE);
@@ -70,6 +80,7 @@ public void drawData(Canvas c) {
}
protected Path mDrawDataSetSurfacePathBuffer = new Path();
+
/**
* Draws the RadarDataSet
*
@@ -89,7 +100,7 @@ protected void drawDataSet(Canvas c, IRadarDataSet dataSet, int mostEntries) {
float factor = mChart.getFactor();
MPPointF center = mChart.getCenterOffsets();
- MPPointF pOut = MPPointF.getInstance(0,0);
+ MPPointF pOut = MPPointF.getInstance(0, 0);
Path surface = mDrawDataSetSurfacePathBuffer;
surface.reset();
@@ -159,8 +170,8 @@ public void drawValues(Canvas c) {
float factor = mChart.getFactor();
MPPointF center = mChart.getCenterOffsets();
- MPPointF pOut = MPPointF.getInstance(0,0);
- MPPointF pIcon = MPPointF.getInstance(0,0);
+ MPPointF pOut = MPPointF.getInstance(0, 0);
+ MPPointF pIcon = MPPointF.getInstance(0, 0);
float yoffset = Utils.convertDpToPixel(5f);
@@ -182,11 +193,11 @@ public void drawValues(Canvas c) {
RadarEntry entry = dataSet.getEntryForIndex(j);
- Utils.getPosition(
- center,
- (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
- sliceangle * j * phaseX + mChart.getRotationAngle(),
- pOut);
+ Utils.getPosition(
+ center,
+ (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
+ sliceangle * j * phaseX + mChart.getRotationAngle(),
+ pOut);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
@@ -216,8 +227,8 @@ public void drawValues(Canvas c) {
Utils.drawImage(
c,
icon,
- (int)pIcon.x,
- (int)pIcon.y,
+ (int) pIcon.x,
+ (int) pIcon.y,
icon.getIntrinsicWidth(),
icon.getIntrinsicHeight());
}
@@ -255,7 +266,7 @@ protected void drawWeb(Canvas c) {
final int xIncrements = 1 + mChart.getSkipWebLineCount();
int maxEntryCount = mChart.getData().getMaxEntryCountSet().getEntryCount();
- MPPointF p = MPPointF.getInstance(0,0);
+ MPPointF p = MPPointF.getInstance(0, 0);
for (int i = 0; i < maxEntryCount; i += xIncrements) {
Utils.getPosition(
@@ -275,21 +286,44 @@ protected void drawWeb(Canvas c) {
int labelCount = mChart.getYAxis().mEntryCount;
- MPPointF p1out = MPPointF.getInstance(0,0);
- MPPointF p2out = MPPointF.getInstance(0,0);
- for (int j = 0; j < labelCount; j++) {
+ MPPointF p1out = MPPointF.getInstance(0, 0);
+ MPPointF p2out = MPPointF.getInstance(0, 0);
+ for (int j = 0; j < labelCount; j++) {
+ if (mChart.isCustomLayerColorEnable()) {
+ innerArea.rewind();
+ paint.setColor(mChart.getLayerColorList().get(j));
+ }
for (int i = 0; i < mChart.getData().getEntryCount(); i++) {
-
float r = (mChart.getYAxis().mEntries[j] - mChart.getYChartMin()) * factor;
Utils.getPosition(center, r, sliceangle * i + rotationangle, p1out);
Utils.getPosition(center, r, sliceangle * (i + 1) + rotationangle, p2out);
c.drawLine(p1out.x, p1out.y, p2out.x, p2out.y, mWebPaint);
+ if (mChart.isCustomLayerColorEnable()) {
+ if (p1out.x != p2out.x) {
+ if (i == 0) {
+ innerArea.moveTo(p1out.x, p1out.y);
+ } else {
+ innerArea.lineTo(p1out.x, p1out.y);
+ }
+ innerArea.lineTo(p2out.x, p2out.y);
+ }
+ }
}
+ if (mChart.isCustomLayerColorEnable()) {
+ temp.set(innerArea);
+ if (!innerArea.isEmpty()) {
+ boolean result = innerArea.op(previousPath, Path.Op.DIFFERENCE);
+ if (result) {
+ c.drawPath(innerArea, paint);
+ }
+ }
+ previousPath.set(temp);
+ }
}
MPPointF.recycleInstance(p1out);
MPPointF.recycleInstance(p2out);
@@ -305,7 +339,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
float factor = mChart.getFactor();
MPPointF center = mChart.getCenterOffsets();
- MPPointF pOut = MPPointF.getInstance(0,0);
+ MPPointF pOut = MPPointF.getInstance(0, 0);
RadarData radarData = mChart.getData();
@@ -362,6 +396,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
}
protected Path mDrawHighlightCirclePathBuffer = new Path();
+
public void drawHighlightCircle(Canvas c,
MPPointF point,
float innerRadius,