我想将1.00和2.00分为1和2.当我尝试将entry.y = Double(value)
更改为entry.y = Int(value)
时,它说它必须是双倍。如何将值转换为整数?
var entries = [PieChartDataEntry]()
for (index, value) in dataarray.enumerated() {
let entry = PieChartDataEntry()
entry.y = Double(value)
entry.label = self.labels[index]
entries.append(entry)
}
这是我正在使用的图表:
答案 0 :(得分:4)
让pieChartView = PieChartView(框架:CGRect(x:60,y:50,宽度:200,高度: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:entries,label:"")
让data = PieChartData(dataSet:set)
pieChartView.data = data
让formatter = NumberFormatter()
formatter.minimumFractionDigits = 0
data.setValueFormatter(DefaultValueFormatter(formatter:formatter))
答案 1 :(得分:0)
而不是:
entry.y = Double(value)
执行:
entry.y = Int(value)
请注意,2.1
,2.2
等会返回2
答案 2 :(得分:0)
试试这个:
%{VARNAME}i