diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle index 3fcd00220f..e12d96e559 100644 --- a/MPChartExample/build.gradle +++ b/MPChartExample/build.gradle @@ -6,7 +6,7 @@ android { compileSdkVersion 31 defaultConfig { applicationId "com.xxmassdeveloper.mpchartexample" - minSdkVersion 16 + minSdkVersion 19 targetSdkVersion 31 versionCode 57 versionName '3.1.0' 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/build.gradle b/MPChartLib/build.gradle index aeb7d6c6f4..0a3c443621 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -6,7 +6,7 @@ plugins { android { compileSdkVersion 31 defaultConfig { - minSdkVersion 14 + minSdkVersion 19 targetSdkVersion 31 consumerProguardFiles 'proguard-project.txt' 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 a7a3123cd7..a1a96507d4 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 337cc1ae7b..0e4abe56c1 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); @@ -282,18 +292,40 @@ protected void drawWeb(Canvas c) { 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);