我想使用不渲染任何x轴或网格线的ios图表渲染(堆叠)水平条形图.我已经禁用了我能找到的每个设置,但是底部的x轴仍然呈现.
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 }
此代码导致以下呈现:
如何删除底轴渲染和垂直值线?
终于想通了.由于这是一个HorizontalBarChart,因此轴的名称稍微偏离.在此图底部渲染的轴实际上是rightAxis.因此,这段代码可以解决问题:
barChart.rightAxis.enabled = false