Skip to content

Commit ebbea06

Browse files
committed
Minor RadarChart fix for unequal datasets in terms of entry count
1 parent 4a8929e commit ebbea06

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

MPChartLib/src/com/github/mikephil/charting/data/ChartData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ private void checkLegal() {
186186
}
187187

188188
/**
189-
* Call this method to let the CartData know that the underlying data has
190-
* changed.
189+
* Call this method to let the ChartData know that the underlying data has
190+
* changed. Calling this performs all necessary recalculations needed when
191+
* the contained data has changed.
191192
*/
192193
public void notifyDataChanged() {
193194
init();

MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,29 @@ public void drawData(Canvas c) {
5757

5858
for (IRadarDataSet set : radarData.getDataSets()) {
5959

60-
if (set.isVisible() && set.getEntryCount() > 0)
61-
drawDataSet(c, set);
60+
if (set.isVisible() && set.getEntryCount() > 0) {
61+
62+
int mostEntries = 0;
63+
64+
for (IRadarDataSet radarSet : radarData.getDataSets()) {
65+
if (set != radarSet && radarSet.getEntryCount() > mostEntries) {
66+
mostEntries = radarSet.getEntryCount();
67+
}
68+
}
69+
70+
drawDataSet(c, set, mostEntries);
71+
}
6272
}
6373
}
6474

65-
protected void drawDataSet(Canvas c, IRadarDataSet dataSet) {
75+
/**
76+
* Draws the RadarDataSet
77+
*
78+
* @param c
79+
* @param dataSet
80+
* @param mostEntries the entry count of the dataset with the most entries
81+
*/
82+
protected void drawDataSet(Canvas c, IRadarDataSet dataSet, int mostEntries) {
6683

6784
float phaseX = mAnimator.getPhaseX();
6885
float phaseY = mAnimator.getPhaseY();
@@ -100,7 +117,15 @@ protected void drawDataSet(Canvas c, IRadarDataSet dataSet) {
100117
surface.lineTo(p.x, p.y);
101118
}
102119

103-
surface.close();
120+
// if this is the largest set, close it
121+
if (dataSet.getEntryCount() >= mostEntries) {
122+
surface.close();
123+
} else {
124+
125+
// if this is not the largest set, draw a line to the center and then close it
126+
surface.lineTo(center.x, center.y);
127+
surface.close();
128+
}
104129

105130
final Drawable drawable = dataSet.getFillDrawable();
106131
if (drawable != null) {

0 commit comments

Comments
 (0)