我目前正在使用Charts,无法找到摆脱这些垂直网格线的方法。这是我得到的图片所具有的一些代码。

for i in 0..<totalExpense.count {
            if totalExpense[i].total != 0 {
                dataEntries.append(BarChartDataEntry(x: Double(i), y: totalExpense[i].total))
                colors.append(randomColor(hue: .random, luminosity: .light))
            }
            else {
                emptyCount += 1
            }
        }

        //Add all the chart data
        if emptyCount != 12 {
            let chartDataSet = BarChartDataSet(entries: dataEntries, label: "")
            let chartData = BarChartData(dataSet: chartDataSet)
            chartDataSet.colors = colors

            let formatter = NumberFormatter()
            formatter.numberStyle = .currency
            chartData.setValueFormatter(DefaultValueFormatter(formatter: formatter))

            barChart.data = chartData
            barChart.data?.setValueTextColor(.black)

            barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: months)
            barChart.xAxis.granularity = 1
            barChart.xAxis.granularityEnabled = true
            barChart.xAxis.labelPosition = .bottom
            barChart.xAxis.labelCount = 12

            barChart.rightAxis.gridColor = .clear

            barChart.leftAxis.enabled = false
            barChart.rightAxis.enabled = false

            barChart.xAxis.drawAxisLineEnabled = false
            barChart.leftAxis.drawGridLinesEnabled = false
            barChart.rightAxis.drawGridLinesEnabled = false

            barChart.legend.enabled = false

ios - Swift图表-条形图垂直网格线-LMLPHP

最佳答案

在库的github repo中的comment中添加以下两行:
barChart.xAxis.gridColor = .clearbarChart.yAxis.gridColor = .clear
这只是一个解决方法,但显然是唯一可行的解​​决方案。

08-03 17:11