如何在 iOS 图表中为标记设置 valueFormatter

How to set valueFormatter for Markers in iOS-charts

对于 y 轴,我们可以这样做:

chartView.leftAxis.valueFormatter = SomeCustomTimeFormatter()

但是我们如何更改标记的格式(点击数据点时出现的弹出窗口)?我正在使用示例代码中的 BalloonMarker。

如果您使用示例中的 BalloonMarker,您可以更新此行中的代码

open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
{
    //setLabel(String(entry.y)) //change label value in this line to use your desired format
   setLabel(String("\(Int(entry.y)/60):\(Int(entry.y)%60)"
}

open func setLabel(_ newLabel: String)
{
        label = newLabel 
        //.......
}

并为您的图表视图设置标记

let marker:BalloonMarker = BalloonMarker(color: UIColor(red: 93/255, green: 186/255, blue: 215/255, alpha: 1), font: UIFont(name: "Helvetica", size: 12)!, textColor: UIColor.white, insets: UIEdgeInsets(top: 7.0, left: 7.0, bottom: 25.0, right: 7.0))
 marker.minimumSize = CGSize(width: 75.0, height: 35.0)
charts.marker = marker