我尝试使用 NSNumberFormatter 将 yAxis 设置为整数,
yAxis.valueFormatter = NSNumberFormatter()
yAxis.valueFormatter.minimumFractionDigits = 0
但这里的问题是我得到重复的 yAxis 值 - 0、1、2、2、3、4 和 5。 如何消除这种情况?
这些是我面临的问题。我试过设置
barChart.leftAxis.axisMaximum = 5.0
barChart.leftAxis.axisMinimum = 0.0
barChart.leftAxis.customAxisMin = 0
barChart.leftAxis.customAxisMax = 5.0
但没有帮助任何建议?
最佳答案
这是无法避免的,因为您不允许小数位。
minimumFractionDigits = 0
表示尽可能没有小数,例如 2.1 和 2.0,它们将导致 2.1 和 2(如果 maximumFractionDigits = 1)
您需要提供信息什么是原始值以及 maximumFractionDigits 的值是什么
编辑:
y 轴标签默认通过internal func computeAxisValues
它根据您的最大值和最小值以及标签计数计算间隔。
如果启用了 _yAxis.isForceLabelsEnabled
,那么它将读取 labelCount
并仅使用 (max-min)/(labelCount-1) 来计算间隔。默认情况下禁用。
当 isForceLabelsEnabled 为 false 时,它有一个小算法来计算什么是获得好看数字的正确方法。
查看internal func computeAxisValues
以找出满足您需求的内容。
更新您问题的第二部分:
- 你不应该触摸 axisMaximum 和 min
- 启用
forceLabelsEnabled
- 将
yAxis.labelCount
更改为 6 或 5 或您喜欢的任何值 - 启用
xAxis.wordWrapEnabled
关于ios - 将 iOS-Charts Float 设置为整数 YAxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33238111/