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:
How do I remove the bottom axis rendering and vertical value lines?
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With