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:
+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 to share