Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lines on Horizontal Bar Chart #2532

Closed
AaronVinh opened this issue Jun 19, 2017 · 2 comments
Closed

Lines on Horizontal Bar Chart #2532

AaronVinh opened this issue Jun 19, 2017 · 2 comments

Comments

@AaronVinh
Copy link

Hi, I'm trying to make my bar chart look like this
screen shot 2017-06-10 at 2 54 53 pm
and this is what I currently am at
screen shot 2017-06-18 at 5 37 21 pm
The problem I have is that there is the small grey line going through each of the bars. It appears to be some kind of gridline. I have tried disabling the grid lines and axes but nothing seems to work.
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)
    //chartDataSet.colors = [UIColor.clear]
    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

    
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        for e in chartEntries{
            let bounds  = self.barChart.getBarBounds(entry: e)
            let gradientLayer = CAGradientLayer()
            gradientLayer.frame = bounds
            gradientLayer.colors = [UIColor(red: 0, green:30,blue:189).cgColor , UIColor(red:2, green:201, blue:255).cgColor]
            gradientLayer.startPoint =  CGPoint(x: 0.0, y: 0.5)
            gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
            self.barChart.layer.addSublayer(gradientLayer)
        }
    }
    `

Any help is greatly appreciated

@thierryH91200
Copy link
Contributor

try

capture d ecran 2017-06-19 a 07 14 23

barChart.xAxis.drawGridLinesEnabled = false

@liuxuan30
Copy link
Member

yes it's because you enabled grid lines like @thierryH91200 said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants