首页 > 解决方案 > 如果 bar 值为 0.0,如何隐藏 markerView。在使用 iOS 图表的条形图中

问题描述

我正在使用 iOS 图表在水龙头上添加标记。我只想在值不为零时打开标记。我们可以使用 iOS 图表库来做到这一点吗?

标签: iosswiftios-charts

解决方案


首先设置 barChartView 的委托,然后在 chartValueSelected 函数中编写这段代码

  func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight){
    if entry.y == 0.0{
        barChartView.highlightValue(nil, callDelegate: false)
    }

}

无论您需要隐藏标记,只需添加此代码

 barChartView.highlightValue(nil, callDelegate: false)

推荐阅读