如何更新IOS图表中的极限线,danielgindi /图表

克里斯·米克森

因此,我添加了一些限制线。

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
}

现在,我想在移动滑块时更新极限线值。在此处输入图片说明

卡姆兰

虽然在Android版本中Charts我们有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)
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章