iOS-图表:minOffset 不工作

iOS-Charts : minOffset not working

当我将 minOffset 设置为 0 时,它不会删除条形图中多余的 padding/margin。

有什么方法可以隐藏 space 吗? 附上屏幕截图,我想从顶部删除多余的 space/padding/margin。

并且如果您将零添加到其中一个柱状图,则此边距将会增加。也附上截图

Extra spacing on top

Margin/space increase if one of the bars value is zero

图的配置参数

func setUpGraph() {
    self.vwChart.chartDescription?.enabled = false
    self.vwChart.drawGridBackgroundEnabled = false
    self.vwChart.drawBordersEnabled = false
    self.vwChart.dragEnabled = false;
    self.vwChart.setScaleEnabled(true)
    self.vwChart.pinchZoomEnabled = false
    self.vwChart.minOffset = 0
    self.vwChart.animate(yAxisDuration: 1.0)

    self.vwChart.xAxis.enabled = false
    self.vwChart.leftAxis.enabled = false
    self.vwChart.leftAxis.inverted = true
    self.vwChart.rightAxis.enabled = false
    self.vwChart.legend.enabled = false

    self.vwChart.xAxis.drawAxisLineEnabled = false
    self.vwChart.leftAxis.drawAxisLineEnabled = false
    self.vwChart.rightAxis.drawAxisLineEnabled = false

    self.vwChart.xAxis.drawGridLinesEnabled = false
    self.vwChart.leftAxis.drawGridLinesEnabled = false
    self.vwChart.rightAxis.drawGridLinesEnabled = false

    self.vwChart.xAxis.drawLabelsEnabled = false
    self.vwChart.xAxis.drawLabelsEnabled = false
    self.vwChart.leftAxis.drawLabelsEnabled = false
    self.vwChart.rightAxis.drawLabelsEnabled = false
}

func setGraphData() {
    var yVals:Array<BarChartDataEntry> = Array<BarChartDataEntry>()

    yVals.append(BarChartDataEntry(x: 0, y: 10))
    yVals.append(BarChartDataEntry(x: 1, y: 5))
    yVals.append(BarChartDataEntry(x: 2, y: 30))
    yVals.append(BarChartDataEntry(x: 3, y: 10))
    yVals.append(BarChartDataEntry(x: 4, y: 50))
    yVals.append(BarChartDataEntry(x: 5, y: 15))
    yVals.append(BarChartDataEntry(x: 6, y: 70))
    yVals.append(BarChartDataEntry(x: 7, y: 20))
    yVals.append(BarChartDataEntry(x: 8, y: 90))
    yVals.append(BarChartDataEntry(x: 9, y: 25))
    yVals.append(BarChartDataEntry(x: 10, y: 110))
    yVals.append(BarChartDataEntry(x: 11, y: 30))
    yVals.append(BarChartDataEntry(x: 12, y: 130))
    yVals.append(BarChartDataEntry(x: 13, y: 35))
    yVals.append(BarChartDataEntry(x: 14, y: 150))
    yVals.append(BarChartDataEntry(x: 15, y: 40))
    yVals.append(BarChartDataEntry(x: 16, y: 170))
    yVals.append(BarChartDataEntry(x: 17, y: 50))
    yVals.append(BarChartDataEntry(x: 18, y: 190))

    let barChartDataSet = BarChartDataSet(values: yVals, label: "")
    barChartDataSet.colors = [UIColor.violetBlue]

    let barChartData = BarChartData(dataSet: barChartDataSet)
    barChartData.barWidth = 0.4
    barChartData.setDrawValues(false)

    self.vwChart.data = barChartData
}

请尝试添加以下行来排列条形图:

self.vwChart.leftAxis.axisMinimum = 0.0

您可以使用 spaceBottom/spaceTop 属性 删除 space。

self.vwChart.leftAxis.spaceBottom = 0.0
self.vwChart.rightAxis.spaceBottom = 0.0

谢谢。 希望这会有所帮助。