You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Daniel Gindi Charts的chartValueSelected对CandleStickChart失效如何解决

解决方案

直接修改代理方法的参数类型不符合ChartViewDelegate的协议定义,系统不会识别该自定义签名的方法,所以不会触发调用。

正确操作是保留协议要求的原方法签名,在方法内部对entry参数做类型转换,转为CandleChartDataEntry类型后即可读取蜡烛图的四个专属参数,示例代码如下:

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
    // 类型转换为蜡烛图专属Entry类型
    guard let candleEntry = entry as? CandleChartDataEntry else { return }
    
    // 读取四个蜡烛图参数
    let highValue = candleEntry.high
    let lowValue = candleEntry.low
    let openValue = candleEntry.open
    let closeValue = candleEntry.close
    
    // 赋值给对应展示标签即可
    highLabel.text = "\(highValue)"
    lowLabel.text = "\(lowValue)"
    openLabel.text = "\(openValue)"
    closeLabel.text = "\(closeValue)"
}

注意:如果类型转换失败,说明当前选中的不是蜡烛图序列的数据,可根据自身业务需求补充额外校验逻辑。

内容的提问来源于stack exchange,提问作者BennyTea

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 14:39:01