所以我添加了一些限制线。
func addLimitLines() {
let stopLoss = ChartLimitLine(limit: Double(1.70) , label: "stop loss")
stopLoss.lineWidth = 0.5
stopLoss.lineColor = .blue
stopLoss.lineDashLengths = [8.0]
chartView.rightAxis.addLimitLine(stopLoss)
let takeProfit = ChartLimitLine(limit: Double(1.68), label: "take profit")
takeProfit.lineWidth = 0.5
takeProfit.lineColor = .blue
takeProfit.lineDashLengths = [8.0]
chartView.rightAxis.addLimitLine(takeProfit)
chartView.reloadInputViews()
}
@IBAction func stopLossChange(_ sender: UISlider) {
//slider action for updating the stoploss limitline
}
@IBAction func takeProfitChange(_ sender: UISlider) {
//slider action for updating the takeprofit limitline
}
答案 0 :(得分:1)
尽管在Charts
的{{3}}版本中,我们有invalidate()
刷新了chartView
,但是在iOS中我看不到它的可用。在iOS中,我使用animate
方法来更新数据,我相信您也可以按以下方式实现此目标,
@IBAction func stopLossChange(_ sender: UISlider) {
self.updateLineLimit(Double(sender.value), label: "stop loss")
}
@IBAction func takeProfitChange(_ sender: UISlider) {
self.updateLineLimit(Double(sender.value), label: "take profit")
}
private func updateLineLimit(_ value: Double, label: String) {
if let line = chartView.rightAxis.limitLines.filter({ $0.label == label }).first {
line.limit = value
chartView.animate(yAxisDuration: 0.00001)
}
}