尽管调用了stringForValue,但XAxis标签未显示

时间:2017-10-03 03:39:57

标签: swift ios-charts

我有一个LineChartView,我想显示xAxis的标签。 我的代码如下所示:

    chartView.chartDescription?.enabled = false
    chartView.drawGridBackgroundEnabled = false
    chartView.dragEnabled = !chartView.isFullyZoomedOut
    chartView.setScaleEnabled(true)
    chartView.pinchZoomEnabled = true
    chartView.setViewPortOffsets(left: 20.0, top: 0.0, right: 20.0, bottom: 0.0)

    chartView.legend.enabled = true
    chartView.legend.textColor = legendColor
    chartView.legend.form = .empty

    chartView.leftAxis.enabled = false
    chartView.leftAxis.spaceTop = 0.4
    chartView.leftAxis.spaceBottom = 0.4
    chartView.rightAxis.enabled = false

    chartView.xAxis.enabled = true
    chartView.xAxis.labelTextColor = UIColor.black
    chartView.xAxis.valueFormatter = self
    chartView.xAxis.drawGridLinesEnabled = false
    chartView.xAxis.drawLabelsEnabled = true
    chartView.xAxis.drawAxisLineEnabled = false

    chartView.highlightPerTapEnabled = false
    chartView.highlightPerDragEnabled = false

    if lineChartData.entryCount > 0 {
        chartView.data = lineChartData
    }
    chartView.noDataText = NSLocalizedString("No chart data available", comment: String())
    chartView.maxVisibleCount = 12
    chartView.delegate = self

extension ChartCell: IAxisValueFormatter {
   func stringForValue(_ value: Double, axis: AxisBase?) -> String {
       return "foo"
   }

}

在调试器中,我看到正在调用stringForValue,但是在绘制的图表中没有标签。 line chart without xAxis labels 我不知道我在这里失踪了什么。

1 个答案:

答案 0 :(得分:1)

您必须在下面进行设置:

chartView.xAxis.labelPosition = XAxis.LabelPosition.bottom