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.
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
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
}`
Disable avoidFirstLastClippingEnabled
. Enabling it will have the effect. It looks like a bug.
Had a similar problem with line charts, the first label on the xAxis is off.
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
}
@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.