iOS 使用 2 个数组制作堆叠条形图的图表
iOS Charts to make Stacked BarChart with 2 arrays
好吧,我正在尝试制作堆积条形图。 (Swift,iOS-来自 cocoapod 的图表。)在这些条件下..
我有 1 个字符串数组和 2 个双精度数组:
1) monthArray = {"1","2","3".....,"12"} //for xAxis Label
2) finalBorrowArray = {0,0,500.0,0,200.0...etc}
3) finalLendArray = {0,0,500.0,800.0,...etc}
这是一些Swift代码:
func setChartData(count:Int, range:UINT32) {
var dataEntries: [ChartDataEntry] = []
var dataEntries2: [ChartDataEntry] = []
for i in 0..<finalBorrowArray.count {
let dataEntry = BarChartDataEntry(x: Double(i), yValues:
[finalBorrowArray[i]])
dataEntries.append(dataEntry)
}
for i in 0..<finalLendArray.count {
let dataEntry = BarChartDataEntry(x: Double(i), yValues:
[finalLendArray[i]])
dataEntries2.append(dataEntry)
}
let yVals = (0..<count).map { (i) -> BarChartDataEntry in
@@@@@@@@@@@@@@@PROBLEM@@@@@@@@@HELP@@@@@@@@@@@@@
return ?
}
}
let set = BarChartDataSet(values:yVals, label: "")
set.drawIconsEnabled = false
set.colors = [ChartColorTemplates.pastel()[0], ChartColorTemplates.pastel()[3]]
set.stackLabels = ["(+)", "(-)"]
let data = BarChartData(dataSet: set)
data.setValueFont(.systemFont(ofSize: 10, weight: 20))
data.setValueFormatter(DefaultValueFormatter(formatter: formatter))
data.setValueTextColor(.black)
barChart.fitBars = true
barChart.data = data
所以我想我必须得到 yVal
作为 BarChartDataEntry
让 yVals。 (也许..?)
但我不知道如何用 2 个 yAxis
得到椭圆...有什么帮助或想法吗?
提前致谢..!
我自己解决了..
我用了另一个 BarChartDataEntry
组合了两个数组,没有用 yVals
.
代码如下:
var finalEntries : [BarChartDataEntry] = []
for i in 0..<finalLendArray.count {
let Entry = BarChartDataEntry(x: Double(i), yValues: [finalBorrowArray[i], finalLendArray[i]])
finalEntries.append(Entry)
}
let set = BarChartDataSet(values:finalEntries, label: "")
好吧,我正在尝试制作堆积条形图。 (Swift,iOS-来自 cocoapod 的图表。)在这些条件下..
我有 1 个字符串数组和 2 个双精度数组:
1)
monthArray = {"1","2","3".....,"12"} //for xAxis Label
2)
finalBorrowArray = {0,0,500.0,0,200.0...etc}
3)
finalLendArray = {0,0,500.0,800.0,...etc}
这是一些Swift代码:
func setChartData(count:Int, range:UINT32) { var dataEntries: [ChartDataEntry] = [] var dataEntries2: [ChartDataEntry] = [] for i in 0..<finalBorrowArray.count { let dataEntry = BarChartDataEntry(x: Double(i), yValues: [finalBorrowArray[i]]) dataEntries.append(dataEntry) } for i in 0..<finalLendArray.count { let dataEntry = BarChartDataEntry(x: Double(i), yValues: [finalLendArray[i]]) dataEntries2.append(dataEntry) } let yVals = (0..<count).map { (i) -> BarChartDataEntry in @@@@@@@@@@@@@@@PROBLEM@@@@@@@@@HELP@@@@@@@@@@@@@ return ? } } let set = BarChartDataSet(values:yVals, label: "") set.drawIconsEnabled = false set.colors = [ChartColorTemplates.pastel()[0], ChartColorTemplates.pastel()[3]] set.stackLabels = ["(+)", "(-)"] let data = BarChartData(dataSet: set) data.setValueFont(.systemFont(ofSize: 10, weight: 20)) data.setValueFormatter(DefaultValueFormatter(formatter: formatter)) data.setValueTextColor(.black) barChart.fitBars = true barChart.data = data
所以我想我必须得到 yVal
作为 BarChartDataEntry
让 yVals。 (也许..?)
但我不知道如何用 2 个 yAxis
得到椭圆...有什么帮助或想法吗?
提前致谢..!
我自己解决了..
我用了另一个 BarChartDataEntry
组合了两个数组,没有用 yVals
.
代码如下:
var finalEntries : [BarChartDataEntry] = []
for i in 0..<finalLendArray.count {
let Entry = BarChartDataEntry(x: Double(i), yValues: [finalBorrowArray[i], finalLendArray[i]])
finalEntries.append(Entry)
}
let set = BarChartDataSet(values:finalEntries, label: "")