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

BarChartView bars do not start at the x-axis. #1225

Closed
jleach opened this issue Jul 6, 2016 · 12 comments
Closed

BarChartView bars do not start at the x-axis. #1225

jleach opened this issue Jul 6, 2016 · 12 comments

Comments

@jleach
Copy link

jleach commented Jul 6, 2016

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

@jleach jleach changed the title Bar chart floats above x-axis BarChartView bars do not start at the x-axis. Jul 6, 2016
@liuxuan30
Copy link
Member

liuxuan30 commented Jul 6, 2016

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

@jleach
Copy link
Author

jleach commented Jul 6, 2016

@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.

@liuxuan30
Copy link
Member

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

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 6, 2016

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

@jleach
Copy link
Author

jleach commented Jul 6, 2016

@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?

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 6, 2016

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.

@liuxuan30 liuxuan30 reopened this Jul 6, 2016
@liuxuan30
Copy link
Member

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.

@liuxuan30
Copy link
Member

@jleach pod install stucks like forever

@jleach
Copy link
Author

jleach commented Jul 6, 2016

@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.

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 6, 2016

@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

@liuxuan30
Copy link
Member

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.. :)

@jleach
Copy link
Author

jleach commented Jul 6, 2016

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.

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

2 participants