Charts: Can't set hole color to nil for Pie Chart

Created on 3 Jan 2016  ·  6Comments  ·  Source: danielgindi/Charts

For a transparent hole, it is recommended to:

*Note: Use holeTransparent with holeColor = nil to make the hole transparent.*```

However, the following set up causes a crash:

pieChart.holeTransparent = true
pieChart.holeColor = nil

Looking at the implementation, the holeColor is explicitly unwrapped, presumably because of the check for nil that precedes it. However, the explicit unwrapping is not in scope of the check:

if (holeColor !== nil && holeColor != UIColor.clearColor())
            {
                // draw the hole-circle
                CGContextSetFillColorWithColor(context, holeColor!.CGColor)
                CGContextFillEllipseInRect(context, CGRect(x: center.x - holeRadius, y: center.y - holeRadius, width: holeRadius * 2.0, height: holeRadius * 2.0))
            }

            // only draw the circle if it can be seen (not covered by the hole)
            if (transparentCircleRadiusPercent > holeRadiusPercent)
            {
                let alpha = holeAlpha * _animator.phaseX * _animator.phaseY
                let secondHoleRadius = radius * transparentCircleRadiusPercent

                // make transparent
                CGContextSetFillColorWithColor(context, holeColor!.colorWithAlphaComponent(alpha).CGColor)

                // draw the transparent-circle
                CGContextFillEllipseInRect(context, CGRect(x: center.x - secondHoleRadius, y: center.y - secondHoleRadius, width: secondHoleRadius * 2.0, height: secondHoleRadius * 2.0))
            }

Temporary workaround:

pieChart.holeColor = UIColor.clearColor()

bug

Most helpful comment

That's a syntax error, should be lowerCase if ;-)

All 6 comments

You are correct :-)
There are still some !s hanging around from the early days of Swift when it wasn't that clear how much unsafe is that !...
Most of them are gone now, thank god!

I think you mean

If let god = god {
    thank(god)
}

Looking forward to testing it out!

😂

That's a syntax error, should be lowerCase if ;-)

I need to include a color shadow inside piechart( like holecolor) corresponding to a particular slice. how can i do that?

how to implement the label instant to create an image in a pie chart
swift 4

Was this page helpful?
0 / 5 - 0 ratings