BarChartView xAxis标签不显示所有标签

Clo*_*ise 3 ios swift ios-charts

我有BarChartView31个酒吧,因此有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
Run Code Online (Sandbox Code Playgroud)

我添加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)
}
Run Code Online (Sandbox Code Playgroud)

Win*_*ero 6

因此,对于x轴,在显示x轴标签时存在axisLabelModulusAxisModulusCustom控制模数.

默认情况下,它会自动计算.

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
Run Code Online (Sandbox Code Playgroud)

您可以使用它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)
Run Code Online (Sandbox Code Playgroud)


Irf*_*fan 6

pod 'Charts', '~> 3.0'
Run Code Online (Sandbox Code Playgroud)

用这个:

public func setLabelCount(count: Int, force: Bool) 
Run Code Online (Sandbox Code Playgroud)