【问题标题】:How do I update the limit lines in IOS Charts, danielgindi/Charts如何更新 IOS Charts, danielgindi/Charts 中的限制线
【发布时间】:2018-07-10 07:10:31
【问题描述】:

所以我添加了几条限制线。

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
}

现在我想在移动滑块时更新限制值。

【问题讨论】:

    标签: ios swift xcode uislider ios-charts


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多