IM使用图表 3.0.1版。 即时通讯目前自学通过转换我的Rails项目斯威夫特。 我没有知识目标C的所以请多多包涵; 我迄今所做OK。
下面我的代码是/可能无法正确格式化为林缺少days
在阵列PieChart
:
数字似乎并不正确。 编码:
@IBOutlet weak var chartView: PieChartView!
override func viewDidLoad() {
super.viewDidLoad()
let days = ["Mo", "Tu", "Wed", "Thur", "Fri", "Sat", "Sun"]
let gross = [11.00, 90.95, 250.00, 40.90, 60.88, 99.99, 25.00]
setChart(dataPoints: days, values: gross)
}
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(x: values[i], y: Double(i))
dataEntries.append(dataEntry)
}
let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "Gross Income")
pieChartDataSet.sliceSpace = 2.0
let pieChartData = PieChartData(dataSets: [pieChartDataSet]) // somewhere here confuses me.
var colors: [UIColor] = []
for _ in 0..<dataPoints.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)
}
pieChartDataSet.colors = colors
chartView.data = pieChartData
}
难道我错过了什么? 你的第二眼将高度赞赏。