1

我尝试使用 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

但没有帮助任何建议?

4

1 回答 1

1

这是无法避免的,因为您不允许使用小数位数。

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
于 2015-10-21T00:46:14.410 回答