Skip to content

Commit edd5132

Browse files
committed
LineDataSet can now enable/disable the hole in circles.
1 parent 143402a commit edd5132

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ private void setData(int count, float range) {
312312
set1.setColor(Color.BLACK);
313313
set1.setCircleColor(Color.BLACK);
314314
set1.setLineWidth(1f);
315-
set1.setCircleSize(4f);
315+
set1.setCircleSize(3f);
316+
set1.setDrawCircleHole(false);
317+
set1.setValueTextSize(9f);
316318
set1.setFillAlpha(65);
317319
set1.setFillColor(Color.BLACK);
318320
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
@@ -323,7 +325,6 @@ private void setData(int count, float range) {
323325

324326
// create a data object with the datasets
325327
LineData data = new LineData(xVals, dataSets);
326-
data.setValueTextSize(10f);
327328

328329
LimitLine ll1 = new LimitLine(130f, "Upper Limit");
329330
ll1.setLineWidth(4f);

‎MPChartLib/src/com/github/mikephil/charting/data/LineDataSet.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
1414

1515
/** arraylist representing all colors that are used for the circles */
1616
private ArrayList<Integer> mCircleColors = null;
17-
17+
1818
/** the radius of the circle-shaped value indicators */
1919
private float mCircleSize = 8f;
2020

@@ -30,6 +30,8 @@ public class LineDataSet extends LineRadarDataSet<Entry> {
3030
/** if true, cubic lines are drawn instead of linear */
3131
private boolean mDrawCubic = false;
3232

33+
private boolean mDrawCircleHole = true;
34+
3335
public LineDataSet(ArrayList<Entry> yVals, String label) {
3436
super(yVals, label);
3537

@@ -269,4 +271,17 @@ public void setCircleColor(int color) {
269271
public void resetCircleColors() {
270272
mCircleColors = new ArrayList<Integer>();
271273
}
274+
275+
/**
276+
* Set this to true to allow drawing a hole in each data circle.
277+
*
278+
* @param enabled
279+
*/
280+
public void setDrawCircleHole(boolean enabled) {
281+
mDrawCircleHole = enabled;
282+
}
283+
284+
public boolean isDrawCircleHoleEnabled() {
285+
return mDrawCircleHole;
286+
}
272287
}

‎MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,35 @@ else if (j == points.size() - 1) {
141141
}
142142
}
143143
}
144-
144+
145145
// if filled is enabled, close the path
146146
if (dataSet.isDrawFilledEnabled()) {
147-
147+
148148
// create a new path, this is bad for performance
149149
drawCubicFill(c, dataSet, new Path(spline), trans);
150-
}
151-
150+
}
151+
152152
mRenderPaint.setColor(dataSet.getColor());
153-
153+
154154
mRenderPaint.setStyle(Paint.Style.STROKE);
155-
155+
156156
trans.pathValueToPixel(spline);
157157

158158
c.drawPath(spline, mRenderPaint);
159-
159+
160160
mRenderPaint.setPathEffect(null);
161161
}
162162

163163
protected void drawCubicFill(Canvas c, LineDataSet dataSet, Path spline, Transformer trans) {
164-
164+
165165
float fillMin = mChart.getFillFormatter()
166166
.getFillLinePosition(dataSet, mChart.getLineData(), mChart.getYChartMax(),
167167
mChart.getYChartMin());
168168

169-
spline.lineTo(dataSet.getYVals().get((int) ((dataSet.getYVals().size() - 1) * mAnimator.getPhaseX())).getXIndex(), fillMin);
169+
spline.lineTo(
170+
dataSet.getYVals()
171+
.get((int) ((dataSet.getYVals().size() - 1) * mAnimator.getPhaseX()))
172+
.getXIndex(), fillMin);
170173
spline.lineTo(mChart.getXChartMin(), fillMin);
171174
spline.close();
172175

@@ -178,7 +181,7 @@ protected void drawCubicFill(Canvas c, LineDataSet dataSet, Path spline, Transfo
178181

179182
trans.pathValueToPixel(spline);
180183
c.drawPath(spline, mRenderPaint);
181-
184+
182185
mRenderPaint.setAlpha(255);
183186
}
184187

@@ -325,12 +328,12 @@ public void drawValues(Canvas c) {
325328

326329
if (!dataSet.isDrawValuesEnabled())
327330
continue;
328-
331+
329332
// apply the text-styling defined by the DataSet
330333
applyValueTextStyle(dataSet);
331334

332335
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
333-
336+
334337
// make sure the values do not interfear with the circles
335338
int valOffset = (int) (dataSet.getCircleSize() * 1.75f);
336339

@@ -355,7 +358,8 @@ public void drawValues(Canvas c) {
355358

356359
float val = entries.get(j / 2).getVal();
357360

358-
c.drawText(dataSet.getValueFormatter().getFormattedValue(val), x, y - valOffset,
361+
c.drawText(dataSet.getValueFormatter().getFormattedValue(val), x,
362+
y - valOffset,
359363
mValuePaint);
360364
}
361365
}
@@ -402,9 +406,11 @@ protected void drawCircles(Canvas c) {
402406

403407
c.drawCircle(x, y, dataSet.getCircleSize(),
404408
mRenderPaint);
405-
c.drawCircle(x, y,
406-
dataSet.getCircleSize() / 2f,
407-
mCirclePaintInner);
409+
410+
if (dataSet.isDrawCircleHoleEnabled())
411+
c.drawCircle(x, y,
412+
dataSet.getCircleSize() / 2f,
413+
mCirclePaintInner);
408414
}
409415
} // else do nothing
410416
}

0 commit comments

Comments
 (0)