将 iOS-Charts Float 设置为整数 YAxis

Setting iOS-Charts Float to Integer YAxis

我尝试使用 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 以找出满足您需求的内容。

更新 问题的第二部分:

  1. 你不应该触摸 axisMaximum 和 min
  2. 启用forceLabelsEnabled
  3. yAxis.labelCount 更改为 6 或 5 或任何你喜欢的值
  4. 启用xAxis.wordWrapEnabled