ChartDataEntry(x: 0, y: 1)
CandleChartDataEntry(x: 0, shadowH: 10, shadowL: 0, open: 0, close: 0)
private func setData() {
var enties: [CandleChartDataEntry] = []
for (i, data) in kDatas.enumerated() {
let e = CandleChartDataEntry(x: Double(i), shadowH: data.high, shadowL: data.low, open: data.open, close: data.close)
enties.append(e)
}
let set1 = CandleChartDataSet(entries: enties, label: nil)
let data = CandleChartData(dataSet: set1)
chart.data = data
}
private func setDataSet(enties: [CandleChartDataEntry]) -> CandleChartDataSet {
let dataset = CandleChartDataSet(entries: enties, label: nil)
dataset.decreasingColor = .green
dataset.increasingColor = .red
dataset.decreasingFilled = true
dataset.increasingFilled = true
dataset.shadowColorSameAsCandle = true
return dataset
}
let set1 = setDataSet(enties: enties)
let data = CandleChartData(dataSet: set1)
private func setDateLine() {
for (i, info) in kDatas.enumerated() {
addDateLimitLine(month: info.time, index: i)
}
}
///增加限制線(月線)
private func addDateLimitLine(month: String, index: Int) {
let monthLimitLine = ChartLimitLine(limit: Double(index), label: month)
monthLimitLine.labelPosition = .bottomLeft
monthLimitLine.lineWidth = 1
monthLimitLine.lineColor = .white
monthLimitLine.valueTextColor = .white
chart.xAxis.addLimitLine(monthLimitLine)
}