ChartsOrg / ChartsOrg/Charts

Horizontal Bar Bounds

Open
#2,515 5 comments 0 reactions 1 assignee Claimed by @liuxuan30 View on GitHub
bug
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I believe that the getBarBounds function is bugged. I am trying to draw a gradient layer over each bar by grabbing the bounds for each bar. Here is my code
`
var chartEntries = [BarChartDataEntry]()

var times = [50,120,150,250,250,350,430,500]
let shows = ["The Wire \n \n ","Game of Thrones \n \n ","The Sopranos \n \n ","Breaking Bad \n \n ","Billions \n \n ","House of Cards \n \n ","Attack on Titan \n \n ", "Mad Men \n \n "]

for i in 0 ..< times.count {
let chartEntry = BarChartDataEntry(x:Double(i), y: Double(times[i]))
chartEntries.append(chartEntry)
//categories[i] = shows[i] + "\n" + String(times[i])
}

let chartDataSet = BarChartDataSet(values: chartEntries, label: "Categories")

let chartData = BarChartData(dataSet: chartDataSet)

chartData.barWidth = 0.2
barChart.leftAxis.axisMinimum = 0
barChart.data = chartData
barChart.chartDescription?.text = ""
barChart.legend.enabled = false
barChart.xAxis.labelPosition = .bottomInside
barChart.leftAxis.enabled = false
barChart.rightAxis.enabled = false
barChart.drawValueAboveBarEnabled = true
barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values:shows)
barChart.xAxis.granularity = 1
barChart.xAxis.drawAxisLineEnabled = false
barChart.drawGridBackgroundEnabled = false
for e in chartEntries{
let bounds = barChart.getBarBounds(entry: e)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = [UIColor(red:2, green:201, blue:255).cgColor,UIColor(red: 0, green:30,blue:189).cgColor]
gradientLayer.locations = [0.5, 1.0]
barChart.layer.addSublayer(gradientLayer)

}`
screen shot 2017-06-11 at 5 47 27 pm

you can see in the screenshot the actualy bars in the light blue color and the gradient layer on top of them. The gradient layers' positions are off as well as the wrong size. Am I misunderstanding how the getBounds functions works or is it bugged?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.