Reputation: 3104
When setting up a horizontal bar chart, I'm actually getting a weird issue where the labels of the leftAxis are clipped.
Here's the code I've used to set up my horizontal bar
func prepareHorizontalBarChart() {
horizontalBarChartView.zoomOut()
horizontalBarChartView.fitBars = true
horizontalBarChartView.xAxis.drawGridLinesEnabled = false // disable horizontal grid lines
horizontalBarChartView.chartDescription?.enabled = false
horizontalBarChartView.xAxis.labelPosition = .bottom
horizontalBarChartView.leftAxis.spaceTop = 0.0
horizontalBarChartView.rightAxis.enabled = false
horizontalBarChartView.leftAxis.axisMinimum = 0
horizontalBarChartView.leftAxis.labelPosition = .insideChart
horizontalBarChartView.leftAxis.granularity = 1.0
horizontalBarChartView.leftAxis.granularityEnabled = true
horizontalBarChartView.extraRightOffset = 10.0
horizontalBarChartView.legend.enabled = false
horizontalBarChartView.xAxis.avoidFirstLastClippingEnabled = true
horizontalBarChartView.xAxis.granularity = 1.0
horizontalBarChartView.xAxis.granularityEnabled = true
horizontalBarChartView.xAxis.drawLabelsEnabled = true
horizontalBarChartView.rightAxis.labelFont = UIFont.systemFont(ofSize: 20)
reloadData()
}
Upvotes: 0
Views: 970
Reputation: 8351
I think in Horizontal Bar chart label is cliping on top edges so for that we need to add extra space in Chart view port with below property.
horiBarChartView.extraTopOffset = 10
will add 10px extra space from top.
Before extra space (default behaviour):
After 10px extra space:
Hope this will help you to solve your problem.
Upvotes: 1