Reputation: 4229
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:
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.
Upvotes: 3
Views: 3133
Reputation: 349
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.
Upvotes: 0
Reputation: 9754
In your sample project, you forgot to set
dataSet.axisDependency = .Right
Upvotes: 4
Reputation: 3545
barChartView.leftAxis.spaceBottom = 0.0
works for me, for you it is .rightAxis
Upvotes: 3
Reputation: 9898
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()
}
}
Upvotes: 0