gpt4 book ai didi

ios - 如何解决图表中多条线的问题

转载 作者:行者123 更新时间:2023-11-30 10:53:40 25 4
gpt4 key购买 nike

我正在尝试在图表中显示我的数据,但是当我尝试使用多行来执行此操作时遇到问题。这些线条表现得很奇怪,我尝试了很多方法,但无法以任何方式修复它。这是这个的图片

Charts

我使用的是 Xcode(版本 10.1 (10B61))、Swift 4.2、Charts 3.2.1

let dollars1 = [1453.0,2352,5431,1442,5451,6486,1173,5678,9234,1345,9411,2212]
let dollars2 = [5641.0,2234,8763,4453,4548,6236,7321,3458,2139,399,1311,5612]
let dollars3 = [6541.0,3456,7843,5678,5877,7323,7111,6456,5143,4562,6311,10412]

var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<dollars1.count {
yVals1.append(ChartDataEntry(x: dollars1[i], y: Double(i)))
}

let set1: LineChartDataSet = LineChartDataSet(values: yVals1, label: "First Set")
set1.axisDependency = .left // Line will correlate with left axis values
set1.setColor(UIColor.red.withAlphaComponent(0.5))
set1.setCircleColor(UIColor.clear)
set1.lineWidth = 2.0
set1.fillAlpha = 65 / 255.0
set1.fillColor = UIColor.red
set1.highlightColor = UIColor.yellow
set1.drawCircleHoleEnabled = false

var yVals2 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<dollars2.count {
yVals2.append(ChartDataEntry(x: dollars2[i], y: Double(i)))
}

let set2: LineChartDataSet = LineChartDataSet(values: yVals2, label: "Second Set")
set2.axisDependency = .left // Line will correlate with left axis values
set2.setColor(UIColor.green.withAlphaComponent(0.5))
set2.setCircleColor(UIColor.clear)
set2.lineWidth = 2.0
set2.fillAlpha = 65 / 255.0
set2.fillColor = UIColor.green
set2.highlightColor = UIColor.yellow
set2.drawCircleHoleEnabled = false

var yVals3 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<dollars3.count {
yVals3.append(ChartDataEntry(x: dollars3[i], y: Double(i)))
}

let set3: LineChartDataSet = LineChartDataSet(values: yVals3, label: "Third Set")
set3.axisDependency = .left // Line will correlate with left axis values
set3.setColor(UIColor.blue.withAlphaComponent(0.5))
set3.setCircleColor(UIColor.clear)
set3.lineWidth = 2.0
set3.fillAlpha = 65 / 255.0
set3.fillColor = UIColor.blue
set3.highlightColor = UIColor.yellow
set3.drawCircleHoleEnabled = false

//3 - create an array to store our LineChartDataSets
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
dataSets.append(set2)
dataSets.append(set3)

//4 - pass our months in for our x-axis label value along with our dataSets
let data: LineChartData = LineChartData(dataSets: dataSets)
data.setValueTextColor(UIColor.white)

//5 - finally set our data
self.lineCharts.data = data

最佳答案

我正在使用 SwiftChart git 库:- https://github.com/gpbl/SwiftChart

点击查看图片 enter image description here

这是代码:-

let chart = Chart(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
let series = ChartSeries([0, 6.5, 2, 8, 4.1, 7, -3.1, 10, 8])
chart.add(series)

关于ios - 如何解决图表中多条线的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54193923/

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