gpt4 book ai didi

IOS Swift Charts3.0 :How to add Xvals

转载 作者:行者123 更新时间:2023-11-30 12:52:44 26 4
gpt4 key购买 nike

在Charts2.3中我们可以使用如下代码来添加数据。

代码:

let chartDataSet = LineChartDataSet(yVals: dataEntries, label: "Units Sold") 
let chartData = LineChartData(xVals: months, dataSet: chartDataSet)

但是在Charts3.0中,我找不到将月份添加到折线图的参数

代码:

var months: [String]!
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]
setChart(dataPoints: months, values: unitsSold)

func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}
let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "test")

let lineChartData = LineChartData()
lineChartData.addDataSet(lineChartDataSet)
self.lineChartView.chartDescription?.text = "TestLinechart"
}

最佳答案

对于以下函数,您可以设置折线图数据的值

  lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)

lineChartView.xAxis.granularity = 1.0

希望这对你有帮助!!!

关于IOS Swift Charts3.0 :How to add Xvals,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40756944/

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