Search code examples
xcodeswiftjbchartview

Gradient in jbchartview


Trying to make the bars a gradient color and cannot find any documentation on how to do this. Looks like this is the right func. Just need help on what to type in the brackets. Not concerned about what color really either.

func barGradientForBarChartView(barChartView: JBBarChartView!) -> CAGradientLayer! {


}

Thanks for the help!


Solution

  • Managed to figure this one out. Figured I would post the code incase anyone else needs. Just remember that it covers all of the bars. You can't separate them by index like with solid bars.

    func barGradientForBarChartView(barChartView: JBBarChartView) -> CAGradientLayer {
        let topColor = UIColor.orangeColor()
        let bottomColor = UIColor.blueColor()
    
        let gradientColors: [CGColor] = [topColor.CGColor, bottomColor.CGColor]
        let gradientLocations: [Float] = [0.0, 1.0]
    
        let gradientLayer: CAGradientLayer = CAGradientLayer()
        gradientLayer.colors = gradientColors
        gradientLayer.locations = gradientLocations
    
        return gradientLayer
    }