How show xAxis label bottom to all column

65 Views Asked by At

i want to show bottom label xAxis to all column, For some reason they only appear to me in the odd places , i using this libary https://cocoapods.org/pods/Charts I'm not sure how to do this, I'd appreciate some help

this result i get:

This is the result I get

code:

import UIKit
import Charts
class BarChart:BarChartView{
    
    struct ViewModel {
        let y:Double
        
    }
    
    private var entries = [BarChartDataEntry]()
    private let barChartDescription = "Internet disconnect num of occurrences"
    private let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        configuration()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        configuration()
    }
    
    
    private func configuration() {
        doubleTapToZoomEnabled = false
        xAxis.labelPosition = .bottom
        leftAxis.axisMinimum = 0.0
        rightAxis.axisMinimum = 0.0
        legend.direction = .leftToRight
        xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
        xAxis.granularity = 1
        
        
        
    }
    
    func setupData(data:[ViewModel]) {
        
        entries.removeAll()
        
        for (index, element) in data.enumerated() {
            print(index)
            entries.append(BarChartDataEntry(x:Double(index), y: element.y))
            
        }
        
        
        let set = BarChartDataSet(entries: entries, label: barChartDescription)
        let data = BarChartData(dataSet: set)
        self.data = data
        
    }
    
    
}

I tried using

xAxis.valueFormatter = IndexAxisValueFormatter(values:months)

 xAxis.granularity = 1

Unfortunately it doesn't work

0

There are 0 best solutions below