使用第三方“图表”。值的输入格式为Double,响应也为double。例如,当输入显示为a=12,b=13,c=20,d=25的图形时,我的输入为a=12.0,b=13.0,c=20.0,d=25.0

ios - 使用第三方的“图表”,响应值将变为两倍。如何将其转换为整数格式?-LMLPHP

这是我的代码

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
}



  我想要没有小数点的值。

最佳答案

只需插入此代码

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




let data = PieChartData(dataSet: set)

关于ios - 使用第三方的“图表”,响应值将变为两倍。如何将其转换为整数格式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45503241/

10-09 02:32