gpt4 book ai didi

swift - 如何在 ios 图表中快速设置字符串和 Y 轴数字

转载 作者:搜寻专家 更新时间:2023-11-01 06:57:20 24 4
gpt4 key购买 nike

我正在寻找使用“ios charts graph”添加标签或字符串的方法,

我希望 y 轴显示为带有“min”字符串的时间(例如 23 分钟、24 分钟等)

我发现每个方法都是针对 x 轴并使用 numberformatter() 但不是针对 y 轴。

需要帮助显示带数字的字符串( double ),如我在上面给出的示例中所示

最佳答案

@MichaelV 为您建议了一个好的开始。只需像为 XAxis 使用它一样为 YAxis 使用自定义值格式化程序。事实上,XAxis 和 YAxis 类具有相同的祖先。

所以你需要声明一个值格式化类:

class YAxisValueFormatter: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return String(value) + " min"
}
}

然后为图表中的左右轴设置此格式化程序:

myChart.leftAxis.valueFormatter = YAxisValueFormatter()
myChart.rightAxis.valueFormatter = YAxisValueFormatter()

关于swift - 如何在 ios 图表中快速设置字符串和 Y 轴数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52721531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com