Swift / chart: chart value int instead of double

I want to rotate 1.00 and 2.00 to 1 and 2. When I try to change entry.y = Double(value)

to entry.y = Int(value)

, it says it should be double. How do I convert values ​​to integers?

var entries = [PieChartDataEntry]()
        for (index, value) in dataarray.enumerated() {
            let entry = PieChartDataEntry()
            entry.y = Double(value)
            entry.label = self.labels[index]
            entries.append(entry)
        }

      

This is the diagram I am using:

Diagram

+3


source to share


3 answers


let pieChartView = PieChartView (frame: CGRect (x: 60, y: 50, width: 200, height: 300))

    let track = ["Passed", "Failed", "Pending"]
    let money = [10, 6, 10]

    var entries = [PieChartDataEntry]()
    for (index, value) in money.enumerated() {
        let entry = PieChartDataEntry()

        entry.y = Double(value)

       entry.label = track[index]
        entries.append( entry)
    }

      

let set = PieChartDataSet (values: records, label: "")

let data = PieChartData (dataSet: set)



pieChartView.data = data p>

let formatter = NumberFormatter ()

formatter.minimumFractionDigits = 0

   data.setValueFormatter(DefaultValueFormatter(formatter:formatter))

      

+2


source


Instead:

entry.y = Double(value)

      

do:



entry.y = Int(value)

      

Please note that 2.1

, 2.2

etc. will return2

0


source


Try the following:

let number = NSNumber(value: value)
entry.y = number.integerValue

      

0


source







All Articles