How to set BarChartDataEntry labels (String not Double) not xaxis labels

387 views Asked by At

Hi all i need help i want to format BarChartDataEntry labels as shown in image. enter image description here

My Code

    var dataEntries: [BarChartDataEntry] = []
    var dataEntriesBottom: [BarChartDataEntry] = []
     for i in 0..<goals.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: Double(goals[i]))
       dataEntries.append(dataEntry)
     }
    let chartDataSet = BarChartDataSet(entries: dataEntries, label: "")
    chartDataSet.colors = [.systemGreen]
    let chartData = BarChartData(dataSet: chartDataSet)
    chartData.barWidth = 0.4
    chartView.xAxis.drawAxisLineEnabled = false
    chartView.leftAxis.drawAxisLineEnabled = false
    chartView.xAxis.drawGridLinesEnabled = false
    chartView.rightAxis.drawAxisLineEnabled = false
    chartView.leftAxis.drawLabelsEnabled = false
    chartView.rightAxis.drawLabelsEnabled = false
    chartView.leftAxis.drawGridLinesEnabled = false
    chartView.rightAxis.drawGridLinesEnabled = false
    chartView.xAxis.enabled = false
    chartView.xAxis.drawLabelsEnabled = false
    chartView.xAxis.granularity = 0
    self.chartView.animate(yAxisDuration: 1.0)
    self.chartView.legend.enabled = false
    chartView.data = chartData
1

There are 1 answers

2
Dima G On

try something like this:

let myFormatter = NumberFormatter()
myFormatter.numberStyle = .decimal
myFormatter.maximumFractionDigits = 0
chartData.setValueFormatter(DefaultValueFormatter(formatter: myFormatter))