Jojo Narte
Jojo Narte

Reputation: 3104

Left axis for HorizontalBarChart of Charts are clipped from the top

When setting up a horizontal bar chart, I'm actually getting a weird issue where the labels of the leftAxis are clipped.

See screenshot: Label clipping

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

Answers (1)

CodeChanger
CodeChanger

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

enter image description here

After 10px extra space:

enter image description here

Hope this will help you to solve your problem.

Upvotes: 1

Related Questions