BarChartView xAxis 标签不显示所有标签

BarChartView xAxis label doesn't display all labels

我有一个 BarChartView 有 31 个小节,因此有 31 个标签。我添加了所有内容并根据示例进行了设置,它按预期工作 - 除了 BarChartView 仅显示每个第三个标签。所以我尝试打印出 1、2、3、4、5、6、...、30、31,但它打印出 1、4、7、11、...、31。我该如何更改它?我什至不需要打印所有标签,我真正需要的只是第一个和最后一个标签,所以 1 和 31,但我一辈子都不知道如何设置它。

我已经尝试将标签设置为 nil 为每个不是第一个或最后一个栏,但这也没有做任何事情。我相信它打印每个第三个标签的原因是因为它无法将它们全部放入,对吗?我对 BarChartView 的设置是:

    barChartView.descriptionText = ""
    barChartView.noDataTextDescription = ""
    barChartView.drawGridBackgroundEnabled = false
    barChartView.xAxis.drawAxisLineEnabled = false
    barChartView.xAxis.drawGridLinesEnabled = false
    barChartView.xAxis.drawLabelsEnabled = true
    barChartView.drawBordersEnabled = false
    barChartView.leftAxis.enabled = false
    barChartView.rightAxis.enabled = false
    barChartView.legend.enabled = false
    barChartView.xAxis.labelPosition = .Bottom
    barChartView.xAxis.labelTextColor = UIColor.whiteColor()
    barChartView.xAxis.labelFont = UIFont(name: timesNewRoman, size: barChartView.xAxis.labelFont.pointSize)!
    barChartView.dragEnabled = false
    barChartView.highlightEnabled = false
    barChartView.scaleXEnabled = false
    barChartView.scaleYEnabled = false

然后我像这样添加 xValues

for (index, value) in plotData.enumerate() {
        var xValue: String?
        xValue = index == 0 || index == plotData.count-1 ? "\(index + 1)" : nil


        barChartData.addXValue(xValue)
        let dataEntry = BarChartDataEntry(value: Double(value), xIndex: index)

        dataEntries.append(dataEntry)
}

所以,对于x轴,有axisLabelModulusAxisModulusCustom来控制显示x轴标签时的模数

默认情况下它是自动计算的。

public var axisLabelModulus = Int(1)
/// Is axisLabelModulus a custom value or auto calculated? If false, then it's auto, if true, then custom.
/// 
/// **default**: false (automatic modulus)
private var _isAxisModulusCustom = false

您可以使用setLabelsToSkip()设置要跳过的标签数量。

/// Sets the number of labels that should be skipped on the axis before the next label is drawn. 
/// This will disable the feature that automatically calculates an adequate space between the axis labels and set the number of labels to be skipped to the fixed number provided by this method. 
/// Call `resetLabelsToSkip(...)` to re-enable automatic calculation.
public func setLabelsToSkip(count: Int)

pod 'Charts', '~> 3.0'

使用这个:

public func setLabelCount(count: Int, force: Bool)