0

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

2
  • tried with xAxis.setLabelCount(months.count, force: true) ? Commented Nov 4, 2022 at 13:29
  • now i get this : ibb.co/9vSgDLC @alessandro_minopoli Commented Nov 4, 2022 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.