我试图在图表中显示数据,但是当我尝试使用多条线进行操作时出现问题。这些行的行为很奇怪,我尝试了很多事情,但是我无法以任何方式解决它。这是这张照片
我正在使用Xcode(版本10.1(10B61)),Swift 4.2,图表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
答案 0 :(得分:0)
我使用SwiftChart git库:-https://github.com/gpbl/SwiftChart
单击以查看图像 enter image description here
这是代码:-
nAlign