ChartsOrg / ChartsOrg/Charts

ChartFill doesn't seem to work - or I'm just not understanding it

Open
#2,727 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I'm using a filled line chart. I want to have a simple gradient from one color to another. All I'm seeing is a single color, no matter if I use a gradient or not.

Here is my code chunks :)

` fileprivate let set_checkin = LineChartDataSet(values: [ChartDataEntry()], label: "Checkins")
`

Yes - its ugly orange to green - its for testing just to see if it works:

` let checkinColors = [UIColor.orange, UIColor.green]
set_checkin.fillAlpha = 1.0
set_checkin.fill = Fill(linearGradient: CGGradient.gradient(withUIColors: checkinColors), angle: 90.0)
set_checkin.drawFilledEnabled = true
`
And here is my gradient extension - I've tried multiple ways to create Gradients - but I just left this one.

`
extension CGGradient {
class func gradient(withUIColors colors: [UIColor]) -> CGGradient {
var colorFloats = [CGFloat]()

for color in colors {
var rSelf:CGFloat = 0, gSelf:CGFloat = 0, bSelf:CGFloat = 0, alpha:CGFloat = 0
color.getRed(&rSelf, green: &gSelf, blue: &bSelf, alpha: &alpha)
colorFloats.append(rSelf)
colorFloats.append(gSelf)
colorFloats.append(bSelf)
colorFloats.append(alpha)
}

let colorSpace = CGColorSpaceCreateDeviceRGB()
return CGGradient(colorSpace: colorSpace, colorComponents: colorFloats, locations: nil, count: colors.count)!
}
}
`
But all I get is a solid color - the first one in the gradient.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided Swift setup using LineChartDataSet, Fill, and the CGGradient extension. Trace how the filled line chart consumes the gradient and compare it with the reported solid first color; done means the filled chart visibly renders the orange-to-green gradient.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.