我正在尝试将数组作为 groupsData 传递。这是 i-schuetz 的组图示例。
fileprivate var chart: Chart?
fileprivate func barsChart(horizontal: Bool) -> Chart {
let labelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFont)
var groupsData: [(title: String, [(min: Double, max: Double)])] = [
("A", [
(0, 40),
(0, 50),
(0, 35)
]),
("B", [
(0, 20),
(0, 30),
(0, 25)
]),
("C", [
(0, 30),
(0, 50),
(0, 5)
]),
("D", [
(0, 55),
(0, 30),
(0, 25),(0, 25)
])
]
var colors: [UIColor] = []
for _ in 0..<groupsData.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)
}
let groups: [ChartPointsBarGroup] = groupsData.enumerated().map {index, entry in
let constant = ChartAxisValueDouble(index)
let bars = entry.1.enumerated().map {index, tuple in
ChartBarModel(constant: constant, axisValue1: ChartAxisValueDouble(5), axisValue2: ChartAxisValueDouble(tuple.max), bgColor: colors[index])
}
return ChartPointsBarGroup(constant: constant, bars: bars)
}
我正在尝试将此数组转换为图表而不是 gropsData。该组可能包含 n 个条。
let months = ["Jan", "Feb", "Mar", "Apr", "May"]
let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0]
let unitsBought = [10.0, 14.0, 60.0, 13.0, 2.0]
我怎样才能做到这一点?
谢谢!