6

I want to render a (stacked) horizontal bar chart using ios-charts that does not render any x axis or grid lines. I've disabled every setting I can find, but the bottom x axis still renders.

func setUpBarChart() {
    // General bar chart settings
    barChart.pinchZoomEnabled = false
    barChart.drawGridBackgroundEnabled = false
    barChart.drawBarShadowEnabled = false
    barChart.drawValueAboveBarEnabled = false
    barChart.drawBordersEnabled = false
    barChart.drawMarkers = false
    barChart.legend.enabled = false
    barChart.descriptionText = ""
    barChart.drawBordersEnabled = false

    // Left-axis settings
    barChart.leftAxis.drawLabelsEnabled = false
    barChart.leftAxis.drawTopYLabelEntryEnabled = false
    barChart.leftAxis.drawAxisLineEnabled = false

    // x-axis settings

    barChart.xAxis.drawAxisLineEnabled = false
    barChart.xAxis.drawGridLinesEnabled = false
    barChart.xAxis.drawLabelsEnabled = false
    barChart.xAxis.enabled = false

    // add some dummy data
    let entry = BarChartDataEntry(values: [10,2,5], xIndex: 0)
    let set = BarChartDataSet(yVals: [entry], label: nil)
    set.colors = [UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor()]
    set.drawValuesEnabled = false

    let data = BarChartData(xVals: [""], dataSet: set)
    barChart.data = data
}

this code results in the following rendering:

Still Renders x axis!!

How do I remove the bottom axis rendering and vertical value lines?

Greg Ferreri
  • 2,652
  • 5
  • 28
  • 38

2 Answers2

7

Finally figured it out. Since this is a HorizontalBarChart the names of the axis are a little off. The axes that renders on the bottom of this graph is actually the rightAxis. Therefore this code does the trick:

barChart.rightAxis.enabled = false
Greg Ferreri
  • 2,652
  • 5
  • 28
  • 38
1

enabling rightAxis will lead to space calcuation. Disable if you don't want it. However, if you do want it take some space, but just not draw values, axis lines, grid lines, checkout drawLabelsEnabled, drawGridLineEnabled, drawAxisLineEnabled

Wingzero
  • 9,644
  • 10
  • 39
  • 80