@@ -45,6 +45,11 @@ public class PieChartRenderer extends DataRenderer {
45
45
protected Paint mTransparentCirclePaint ;
46
46
protected Paint mValueLinePaint ;
47
47
48
+ /**
49
+ * paint object used for drawing the rounded corner slice
50
+ */
51
+ protected Paint mRoundedCornerPaint ;
52
+
48
53
/**
49
54
* paint object for the text that can be displayed in the center of the
50
55
* chart
@@ -68,6 +73,24 @@ public class PieChartRenderer extends DataRenderer {
68
73
69
74
protected Canvas mBitmapCanvas ;
70
75
76
+ /**
77
+ * Setter for the rounded corner slice paint object
78
+ */
79
+ public void setRoundedCornerRadius (float radius ){
80
+ mRoundedCornerPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
81
+ mRoundedCornerPaint .setStyle (Style .STROKE );
82
+ mRoundedCornerPaint .setAntiAlias (true );
83
+ mRoundedCornerPaint .setStrokeWidth (radius );
84
+
85
+ }
86
+
87
+ /**
88
+ * Getter for the rounded corner slice paint object
89
+ */
90
+ public float getRoundedCornerRadius (){
91
+ return mRoundedCornerPaint .getStrokeWidth ();
92
+ }
93
+
71
94
public PieChartRenderer (PieChart chart , ChartAnimator animator ,
72
95
ViewPortHandler viewPortHandler ) {
73
96
super (animator , viewPortHandler );
@@ -245,6 +268,11 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
245
268
246
269
final float sliceSpace = visibleAngleCount <= 1 ? 0.f : getSliceSpace (dataSet );
247
270
271
+ if (getRoundedCornerRadius ()>0 ) {
272
+ mRoundedCornerPaint .setStrokeCap (Paint .Cap .ROUND );
273
+ mRoundedCornerPaint .setStrokeJoin (Paint .Join .ROUND );
274
+ }
275
+
248
276
for (int j = 0 ; j < entryCount ; j ++) {
249
277
250
278
float sliceAngle = drawAngles [j ];
@@ -268,6 +296,9 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
268
296
269
297
mRenderPaint .setColor (dataSet .getColor (j ));
270
298
299
+ // Set current data set color to paint object
300
+ mRoundedCornerPaint .setColor (dataSet .getColor (j ));
301
+
271
302
final float sliceSpaceAngleOuter = visibleAngleCount == 1 ?
272
303
0.f :
273
304
sliceSpace / (Utils .FDEG2RAD * radius );
@@ -398,6 +429,11 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
398
429
399
430
mBitmapCanvas .drawPath (mPathBuffer , mRenderPaint );
400
431
432
+ // Draw rounded corner path with paint object slice with the given radius
433
+ if (getRoundedCornerRadius ()>0 ) {
434
+ mBitmapCanvas .drawPath (mPathBuffer , mRoundedCornerPaint );
435
+ }
436
+
401
437
angle += sliceAngle * phaseX ;
402
438
}
403
439
0 commit comments