Horizontal Bar Chart Labels

Viewed 3243

I recently upgraded one of my client projects from Swift2 and iOS-charts 2 to Swift3 and iOS-charts 3.

Most of the code is functioning as expected after a few days of manual tweaking, however, I am still having an issue with my horizontal bar chart.

The chart used to display as:

enter image description here

The chart now displays as:

enter image description here

Core code for the chart:

func drawMarginChart() {
    let labels = marginObject!.getLabelsForChart()
    let values = marginObject!.getValuesForChart()

    var dataEntries = [ChartDataEntry]()

    for i in 0..<values.count {
        let entry = BarChartDataEntry(x: Double(i), y: values[i])
        dataEntries.append(entry)
    }

    let barChartDataSet = BarChartDataSet(values: dataEntries, label: "")
    barChartDataSet.drawValuesEnabled = false
    barChartDataSet.colors = ChartColorTemplates.joyful()

    let barChartData = BarChartData(dataSet: barChartDataSet)
    barChartMargins.data = barChartData
    barChartMargins.legend.enabled = false

    barChartMargins.xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)
    barChartMargins.xAxis.granularityEnabled = true
    barChartMargins.xAxis.granularity = 1

    barChartMargins.animate(xAxisDuration: 3.0, yAxisDuration: 3.0, easingOption: .easeInOutBounce)
}

What I am hoping to find out is:

1) How can I get the label to appear for each bar on the chart

2) How can I get the chart to resize automatically to display the labels

If these other issues could be addressed, that would be fantastic, but we are willing to ship it without these:

1) How can I remove the gridline overlap on the left side of the chart?

2) How can I keep the bottom of the chart from truncating?

I have tried adjusting many of the chart properties per posts I have found here and on other sites, however, nothing fixes the issues. Any help it making the chart appear like the old version would be greatly appreciated by myself and my client.

1 Answers
Related