gpt4 book ai didi

swift - iOS 图表 条形图组合图表

转载 作者:行者123 更新时间:2023-11-30 10:24:19 26 4
gpt4 key购买 nike

我正在使用 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
}

我得到的只是这个:

enter image description here

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

[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
}

关于swift - iOS 图表 条形图组合图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60159162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com