swift / charts:图表值int而不是double

时间:2017-06-27 17:58:53

标签: ios swift charts ios-charts

我想将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)
        }

这是我正在使用的图表:

Chart

3 个答案:

答案 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.12.2等会返回2

答案 2 :(得分:0)

试试这个:

%{VARNAME}i