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

BarChart xAxis label offsets #1874

Open
shayneptorres opened this issue Nov 22, 2016 · 4 comments
Open

BarChart xAxis label offsets #1874

shayneptorres opened this issue Nov 22, 2016 · 4 comments
Labels

Comments

@shayneptorres
Copy link

shayneptorres commented Nov 22, 2016

Hello again, first off I want to say thank you for responding to my last issue so quickly. I do have another question though. When creating a bar charts, with labels on the bottom, the very first label is offset and not directly under the respective bar.
screen shot 2016-11-22 at 3 25 27 pm I took a look at the demo and I matched all my settings accordingly: chartView.isUserInteractionEnabled = false chartView.chartDescription?.text = "" chartView.drawBarShadowEnabled = false chartView.rightAxis.drawGridLinesEnabled = false chartView.rightAxis.drawAxisLineEnabled = false chartView.rightAxis.drawLabelsEnabled = false chartView.xAxis.avoidFirstLastClippingEnabled = true chartView.xAxis.centerAxisLabelsEnabled = false chartView.xAxis.drawLimitLinesBehindDataEnabled = false chartView.xAxis.labelPosition = .bottom chartView.xAxis.labelCount = 3 chartView.xAxis.axisMinimum = -0.5 chartView.xAxis.axisMaximum = 3 chartView.xAxis.drawGridLinesEnabled = false chartView.fitBars = true chartView.xAxis.granularity = 1 Im not sure what other properties to try. I would appreciate the guidance. Thanks again

@shayneptorres
Copy link
Author

Here is the entire function I call to setup the graph `func setUpChart(delegate: IAxisValueFormatter){

    var dataEntries = [BarChartDataEntry]()
    var barChartDataSet = BarChartDataSet()
    
    for i in 0..<items.count {
        let de = BarChartDataEntry(x: Double(i), yValues: [itemsValues[i]])
        dataEntries.append(de)
    }
    
    
    barChartDataSet = BarChartDataSet(values: dataEntries , label: "Monthly Income")
    
    chartView.isUserInteractionEnabled = false
    chartView.chartDescription?.text = ""
    chartView.drawBarShadowEnabled = false
    chartView.rightAxis.drawGridLinesEnabled = false
    chartView.rightAxis.drawAxisLineEnabled = false
    chartView.rightAxis.drawLabelsEnabled = false
    chartView.xAxis.avoidFirstLastClippingEnabled = true
    chartView.xAxis.centerAxisLabelsEnabled = false
    chartView.xAxis.drawLimitLinesBehindDataEnabled = false
    chartView.xAxis.labelPosition = .bottom
    chartView.xAxis.labelCount = 3
    chartView.xAxis.axisMinimum = -0.5
    chartView.xAxis.axisMaximum = 3
    chartView.xAxis.drawGridLinesEnabled = false
    chartView.fitBars = true
    chartView.xAxis.granularity = 1
    chartView.xAxis.valueFormatter = delegate

    
    barChartDataSet.colors = ChartColorTemplates.colorful()
    
    
    self.chartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .easeInOutCirc)
    
    let bcData = BarChartData(dataSet: barChartDataSet)
    
    bcData.barWidth = 0.5
    self.chartView.data = bcData
    
    
}`

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 29, 2016

Disable avoidFirstLastClippingEnabled. Enabling it will have the effect. It looks like a bug.

@liuxuan30 liuxuan30 added the bug label Nov 29, 2016
@Rnorback
Copy link

Had a similar problem with line charts, the first label on the xAxis is off.

screen shot 2016-11-29 at 3 28 53 pm

The only way I found to fix it is to use xAxis.centerAxisLabelsEnabled = true but I'm guessing my highlighting will be off.

Here is my xAxis code. Any help is welcome.

 func setupXAxisFormatting() {
        let xAxis = lineChartView.xAxis
        xAxis.enabled = true
        xAxis.drawGridLinesEnabled = false
        xAxis.drawLabelsEnabled = true
        xAxis.drawAxisLineEnabled = false
        xAxis.centerAxisLabelsEnabled = true //would rather fix another way
        
        xAxis.labelPosition = .bottom
        xAxis.labelTextColor = UIColor.gray
        xAxis.labelFont = UIFont(name: Constants.Fonts.ProximaNovaBold, size: 15.0)!
        
        xAxis.avoidFirstLastClippingEnabled = true
        xAxis.spaceMin = 5
        xAxis.valueFormatter = axisFormatDelegate
    }

@liuxuan30
Copy link
Member

@Rnorback I don't think it's the same issue for "the first label on the xAxis is off"? turn off avoidFirstLastClippingEnabled should move '11/23' to left by some space.

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

No branches or pull requests

3 participants