[英]How do you select/highlight a part of the chart through code? (Charts- PieChartView)
[英]Swift Charts- Bar Chart Vertical Grid Lines
我目前正在使用圖表,無法找到擺脫這些垂直網格線的方法。 這是我擁有的一些代碼,可以獲取圖片的內容。
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
從庫的github repo中的此注釋中添加以下兩行:
barChart.xAxis.gridColor = .clear
barChart.yAxis.gridColor = .clear
這只是一種解決方法,但顯然是唯一可行的解決方案。
上面的答案是一種出路,但您可以使用一行代碼來使用網格線的啟用屬性
這是代碼
barChart.xAxis.drawGridLinesEnabled = true
並提前歡迎😊😍
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.