gpt4 book ai didi

ios - 错误 - 无法使用类型为 'LineChartData' 的参数列表调用类型为 '(xVals: [String], dataSet: LineChartDataSet)' 的初始值设定项

转载 作者:行者123 更新时间:2023-11-28 06:11:05 27 4
gpt4 key购买 nike

我目前正在使用 Charts在我的应用程序中使用折线图的框架。我使用了下面的代码,但发生了错误。这是代码-

`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)


var colors: [UIColor] = []

for i 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)
}



let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Sold")

let lineChartDataa = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)

Graph.data = lineChartDataa

}
`

发生的错误如下-

Cannot invoke initializer for type 'LineChartData' with an argument list of type '(xVals: [String], dataSet: LineChartDataSet)'

关于如何解决这个问题的任何想法。

最佳答案

你必须这样使用:

这是设置LineChartData:

let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Sold")     
let lineChartDataa = LineChartData(dataSet: lineChartDataSet)

用于设置 xAxis 标签:

Graph.xAxis.labelPosition = XAxis.LabelPosition.bottom
Graph.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)

关于ios - 错误 - 无法使用类型为 'LineChartData' 的参数列表调用类型为 '(xVals: [String], dataSet: LineChartDataSet)' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46582044/

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