Charts: BarChartView bars do not start at the x-axis.

Created on 6 Jul 2016  Â·  12Comments  Â·  Source: danielgindi/Charts

I can not get an iOS-charts bar chart to put the bars zero (the bottom of the bars) on the x-axis. They seem to float just above the x-axis. As you can see in the attached image the bars are not sitting flush with the x-axis. One difference in my sample project is, if you look at the screenshot (in the screenshots directory) the y-axis zero label is on the x-axis while in the attached image it floats above the x-axis.

This issue might relate to #947

I've created this StackOverflow issue for public support and to better illustrate the issue
http://stackoverflow.com/questions/38064460/ios-charts-wont-put-the-x-axis-at-zero-on-the-y-axis

And I've created this GitHub project to re-create the issue:
https://github.com/jleach/BarChartBug

eatqp

Most helpful comment

@jleach man, you forgot dataSet.axisDependency = .Right

        // create a data set
        let dataSet = BarChartDataSet(yVals: data, label: "")
        dataSet.drawValuesEnabled = false
        dataSet.colors = barColors
        dataSet.axisDependency = .Right // <-- where is it?
        return dataSet

All 12 comments

for newer release, you have to call axisMinValue = 0, startAtZero is deprecated
second,

    override func viewDidLoad() {
        super.viewDidLoad()

        let data = barChartDataSets()
        let xVals = Array(0..<numberOfBars).map { "\($0)" }

        barChartView.data = BarChartData(xVals: xVals , dataSet: data) <-- revert the order with styleBarChart
        styleBarChart(barChartView)
    }

You have to style the chart and then set chart data, or you have to call notiftyDataSetChanged() after styling

@liuxuan30 Why did you close this issue? startAtZero is _not_ being used. I have axisMinValue = 0 in both the example project on GitHub and when I created the image above.

@jleach I have updated my first post. Does it solve your issue?

BTW, I can't compile your project, saying

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory

It's better to have a pure project without any pod/carthage dependency

@liuxuan30 I tried both your suggestions and it has no effect. I committed the change(s) to the sample project.

Do you mean check in the Pods directory or just add Charts directly to the project?

I just need to know how to compile your project, it's complaining about pod, but I don't know what I have to do

PhaseScriptExecution [CP]\ Check\ Pods\ Manifest.lock /Users/xuanliu/Library/Developer/Xcode/DerivedData/ChartBug-bhhhjldmbswlkaafdncvyybvfkbm/Build/Intermediates/ChartBug.build/Debug-iphonesimulator/ChartBug.build/Script-D0AFBB4B11DB1C51D2A5C28B.sh
    cd /Users/xuanliu/Downloads/BarChartBug-master
    /bin/sh -c /Users/xuanliu/Library/Developer/Xcode/DerivedData/ChartBug-bhhhjldmbswlkaafdncvyybvfkbm/Build/Intermediates/ChartBug.build/Debug-iphonesimulator/ChartBug.build/Script-D0AFBB4B11DB1C51D2A5C28B.sh

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

alright, I went to your project folder and run pod install and waiting Setting up CocoaPods master repo.
Now is my work time, so hopefully I can get you something in the noon or maybe later.

@jleach pod install stucks like forever

@liuxuan30 I just checked in the Pods directory; it should not have any more dependencies. Try a git pull and see if that solves the problem.

@jleach man, you forgot dataSet.axisDependency = .Right

        // create a data set
        let dataSet = BarChartDataSet(yVals: data, label: "")
        dataSet.drawValuesEnabled = false
        dataSet.colors = barColors
        dataSet.axisDependency = .Right // <-- where is it?
        return dataSet

I spend 3x time trying to get your project running, at last I create a new project and copy your code instead and fix the storyboard missing connections.
Next time, please create a one-click runable project.. :)

That was it. I appreciate your help; I would not have caught this. I assumed that because I did chartView.leftAxis.enabled = false and chartView.rightAxis.enabled = true that it new my intention was to have a right axis but I see now it needs to be sent in multiple places. Thanks again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guoyutaog picture guoyutaog  Â·  3Comments

ahmedsafadii picture ahmedsafadii  Â·  3Comments

brytnvmg picture brytnvmg  Â·  4Comments

kirti0525 picture kirti0525  Â·  3Comments

Bharati555 picture Bharati555  Â·  4Comments