gpt4 book ai didi

ios - 使用第3方 "charts",响应值为 double 。它如何变成整数格式?

转载 作者:行者123 更新时间:2023-11-30 12:15:18 33 4
gpt4 key购买 nike

使用第三方“图表”。值的输入格式是Double,响应也是Double。例如,我的输入是a=12,b=13,c=20,d=25 当出现类似 a=12.0,b=13.0,c=20.0,d=25.0

的图表时

I want get values as, 12,13,20,25

这是我的代码

func updateChartData()  {

let skipped = 12
let correct = 13
let wrong = 20
let timedOut = 25

let track = ["Skipped", "Right", "Wrong", "Not Attended"]
let money = [skipped, correct, wrong, timedOut]

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

// 3. chart setup
let set = PieChartDataSet( values: entries, label: "Pie Chart")
// this is custom extension method. Download the code for more details.
var colors: [UIColor] = []

for _ in 0..<money.count {
let red = Double(arc4random_uniform(256))
let green = Double(arc4random_uniform(256))
let blue = Double(arc4random_uniform(256))
let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
colors.append(color)
}
set.colors = colors
let data = PieChartData(dataSet: set)
viewPieCharts.data = data
viewPieCharts.noDataText = "No data available"
// user interaction
viewPieCharts.isUserInteractionEnabled = true

let d = Description()
d.text = "iOSCharts.io"
viewPieCharts.chartDescription = d
viewPieCharts.centerText = "Pie Chart"
viewPieCharts.holeRadiusPercent = 0.5
viewPieCharts.transparentCircleColor = UIColor.clear
}

I want the values without decimal point.

最佳答案

只需插入此代码

let format = NumberFormatter()
format.numberStyle = .none
let formatter = DefaultValueFormatter(formatter: format)
data.setValueFormatter(formatter)

之后

let data = PieChartData(dataSet: set)

关于ios - 使用第3方 "charts",响应值为 double 。它如何变成整数格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45503241/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com