Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide bottom x axis in horizontal bar chart?

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?

like image 958
Greg Ferreri Avatar asked Dec 29 '15 20:12

Greg Ferreri


People also ask

How do you hide the x-axis in a chart?

Hide and Display Chart Axes Select Chart Elements, the plus sign (+), to open the Chart Elements menu. To hide all axes, clear the Axes check box. To hide one or more axes, hover over Axes to display a right arrow. Select the arrow to display a list of axes that can be displayed or hidden on the chart.

How do I hide the x-axis labels in Excel?

Click anywhere in the chart for which you want to display or hide axes. This displays the Chart Tools, adding the Design, Layout, and Format tabs. On the Layout tab, in the Axes group, click Axes. Click the type of axis that you want to display or hide, and then click the options that you want.


2 Answers

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
like image 56
Greg Ferreri Avatar answered Oct 19 '22 20:10

Greg Ferreri


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

like image 1
Wingzero Avatar answered Oct 19 '22 22:10

Wingzero