3

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:

enter image description here

The bars in orange are set to 100 which is the max height of the y-axis for illustration. The only thing that might be doing it is at about 3PM there is a blank space.

I have rightAxis.axisMinValue = 0 set.

Shade
  • 9,936
  • 5
  • 60
  • 85
Jason Leach
  • 3,889
  • 7
  • 37
  • 54

4 Answers4

4

In your sample project, you forgot to set dataSet.axisDependency = .Right

Wingzero
  • 9,644
  • 10
  • 39
  • 80
3
barChartView.leftAxis.spaceBottom = 0.0

works for me, for you it is .rightAxis

AnthonyR
  • 3,485
  • 1
  • 18
  • 41
0

I have just work around, This works for me.

Just refer this code.

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var barChartView: BarChartView!

    override func viewDidLoad() {
    super.viewDidLoad()

        let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
        let unitsSold = [20.0, 4.0, 6.0, 3.0, 0.0, 16.0]

        setChart(months, values: unitsSold)

    }


    func setChart(dataPoints: [String], values: [Double]) {

        var dataEntries: [BarChartDataEntry] = []

        for i in 0..<dataPoints.count {
            let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
            dataEntries.append(dataEntry)
        }

        let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
        let chartData = BarChartData(xVals: dataPoints, dataSet: chartDataSet)
        barChartView.data = chartData

        chartDataSet.colors = ChartColorTemplates.colorful()
    }  
}

enter image description here

Hasya
  • 9,792
  • 4
  • 31
  • 46
0

Have you tried setting the right y-axis minimum to zero (rightAxisY.axisMinimum = 0)? That should set the y-axis minimum to the zero line and shift the entire chart downward.

You might also try enabling the zero line (rightAxisY.drawZeroLineEnabled = true) and eliminate the zero value from your data since you are setting zero as the minimum by enabling the zero line.

B-Rad
  • 353
  • 3
  • 11