iOS 条形图组合图

iOS Charts Bar-Bar Combined-Charts

我正在使用 iOS charts 库并尝试制作条形图组合图表。

我不确定这是否可行,但我没有看到关于文档的任何限制,所以我假设有这样的选项。

这是我用来添加组合图表的代码:

func createIntegratedChartForStat(stat:String, chart:CombinedChartView){
    chart.noDataText = "You need to provide data for the " + stat + " chart"

    var dataEntriesTotal: [BarChartDataEntry] = []
    var dataEntriesGood: [BarChartDataEntry] = []
    for i in 0..<gamesOrder.count {
        let outFromStat = playersFullData["b"]![stat]![i]
        var splittedData = outFromStat.split(separator: "/")
        let dataEntryTotal = BarChartDataEntry(x: Double(i), y: Double(splittedData[0])!)
        let dataEntryGood = BarChartDataEntry(x: Double(i), y: Double(splittedData[1])!)
        dataEntriesTotal.append(dataEntryTotal)
        dataEntriesGood.append(dataEntryGood)
    }

    let chartDataSetTotal = BarChartDataSet(values: dataEntriesTotal, label: stat + " Attempts")
    let chartDataSetGood = BarChartDataSet(values: dataEntriesGood, label: stat + " Successful")

    let chartData = CombinedChartData(dataSets: [chartDataSetTotal, chartDataSetGood])

    chart.data = chartData
}

我得到的是这个:

如果我触摸图表,会出现以下错误:

[Unknown process name] CGAffineTransformInvert: singular matrix.

这可以完成还是我遗漏了什么?

有可能,我刚刚把数据添加到组合图表中是错误的。 添加更新的代码:

func createIntegratedChartForStat(stat:String, chart:CombinedChartView){
    chart.noDataText = "You need to provide data for the " + stat + " chart"

    var dataEntriesTotal: [BarChartDataEntry] = []
    var dataEntriesGood: [BarChartDataEntry] = []
    for i in 0..<gamesOrder.count {
        let outFromStat = playersFullData["b"]![stat]![i]
        var splittedData = outFromStat.split(separator: "/")
        let dataEntryTotal = BarChartDataEntry(x: Double(i), y: Double(splittedData[0])!)
        let dataEntryGood = BarChartDataEntry(x: Double(i), y: Double(splittedData[1])!)
        dataEntriesTotal.append(dataEntryTotal)
        dataEntriesGood.append(dataEntryGood)
    }

    let chartDataSetTotal = BarChartDataSet(values: dataEntriesTotal, label: stat + " Attempts")
    chartDataSetTotal.colors = [NSUIColor .blue]
    let chartDataSetGood = BarChartDataSet(values: dataEntriesGood, label: stat + " Successful")
    chartDataSetGood.colors = [NSUIColor .green]

    let chartData = BarChartData(dataSets: [chartDataSetTotal, chartDataSetGood])

    let data: CombinedChartData = CombinedChartData()
    data.barData = chartData
    chart.data = data
}