Copy @IBOutlet weak var chart: CombinedChartView !
Copy private func getLData () -> LineChartData {
var enties: [ChartDataEntry] = []
for ( i, data ) in lineDatas. enumerated () {
let e = ChartDataEntry ( x : Double ( i ) , y : data.price )
enties. append ( e )
}
let set1 = setLDataSet ( enties : enties )
let cData = LineChartData ( dataSet : set1 )
return cData
}
private func setLDataSet ( enties : [ChartDataEntry]) -> LineChartDataSet {
let dataset = LineChartDataSet ( entries : enties, label : nil )
dataset.colors = [.yellow]
dataset.drawCirclesEnabled = false
dataset.drawValuesEnabled = false
return dataset
}
Copy private func setData() {
let data = CombinedChartData()
data.candleData = getCData()
data.lineData = getLData()
chart.data = data
}
Copy chart.xAxis.axisMinimum = -0.5
Copy chart.xAxis.axisMaximum = Double(lineDatas.count) - 0.5
Copy for i in 1...5 {
let number = Double(i) * 10
// let data = LineData(time: "\(i)月", price: number - 1)
//axisDependency介紹
let data = LineData(time: "\(i)月", price: (number - 1)/100)
datas.append(data)
}
Copy let dataset = LineChartDataSet(entries: enties, label: nil)
dataset.axisDependency = .left
-------
let dataset = CandleChartDataSet(entries: enties, label: nil)
dataset.axisDependency = .right