[英]How do I update the limit lines in IOS Charts, danielgindi/Charts
So I have added a couple of limit lines. 所以我添加了几个限制线。
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
}
Now I want to update the limitline values whenever I move the sliders. 现在,我想在移动滑块时更新限制线值。
Although in Android version of Charts
we have invalidate()
that refreshes the chartView
but in iOS i don't see its available. 虽然在Android版本的
Charts
我们有invalidate()
刷新chartView
但在iOS中我看不到它可用。 In iOS i use to update data with animate
methods and i believe you can also achieve this as follows, 在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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.