Search code examples
ios-charts

iOS-Charts : minOffset not working


When I am setting minOffset to 0, it's not removing the extra padding/margin in the bar chart.

Is there any way to hide that space? attached the screenshot, I like to remove that extra space/padding/margin from the top.

and if you add zero to one of the bars then this margin will increase. Attaching the screenshot for that too

Extra spacing on top

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

Configuration parameters of graphs

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
}

Solution

  • Please try to add the below line to line up the bars :

    self.vwChart.leftAxis.axisMinimum = 0.0