4

ios-charts is a cool library I'm using recently.

This is the expected highlighting slice:

enter image description here

This is my current highlighting effect:

enter image description here

The difference is the highlighted effect is too much than I expected.

I wonder which method can I use to adjust the highlighting effect?

Ranger Way
  • 539
  • 6
  • 11

2 Answers2

8

Thanks for @Wingzero's answer.

However I do not want to change the source code or override some methods of it.

Finally, I found the property for the highlight effect of selected slice. It is a property of @interface PieChartDataSet : ChartDataSet.

/// indicates the selection distance of a pie slice
@property (nonatomic) CGFloat selectionShift; 

By setting it as dataSet.selectionShift = 7.0;, it works for my design.

Here attaches the object of dataSet:

PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithYVals:yVals1 label:NULL];
dataSet.selectionShift = 7.0;
PieChartData *data = [[PieChartData alloc] initWithXVals:nil dataSet:dataSet];
self.pieChartView.data = data;

This is the effect what I have expected.

enter image description here

Ranger Way
  • 539
  • 6
  • 11
  • good catch! I forgot to take look at PieChartDataSet if any useful. But I have done customzation so I often subclass the chart and override it. – Wingzero Jul 21 '15 at 08:53
1

You can change yourself:

In PieChartRenderer.swift:

public override func drawHighlighted(#context: CGContext, indices: [ChartHighlight])
{
    if (_chart.data === nil)
    {
        return
    }

    CGContextSaveGState(context)

    var rotationAngle = _chart.rotationAngle
    var angle = CGFloat(0.0)

    var drawAngles = _chart.drawAngles
    var absoluteAngles = _chart.absoluteAngles

    var innerRadius = drawHoleEnabled && holeTransparent ? _chart.radius * holeRadiusPercent : 0.0
...
}

You can change innerRadius or holeTransparent whatever you like to try.

Wingzero
  • 9,644
  • 10
  • 39
  • 80