gpt4 book ai didi

swift - 如何禁用出现在月份标签后面的 X 轴下方的 0.0 数字?

转载 作者:行者123 更新时间:2023-11-30 10:31:45 24 4
gpt4 key购买 nike

如何禁用出现在月份标签后面的 X 轴下方的 0.0 数字?我尝试禁用一些 xAxis 属性但没有成功,我正在使用 IOS 图表。

@IBOutlet weak var chartView: BarChartView!

var completedGoals = [Double]()
var totalGoals = [Double]()
let months = ["Jan", "Feb", "Mar", "Apr", "May","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]

func configure() {
chartView.delegate = self as? ChartViewDelegate
chartView.isUserInteractionEnabled = false
chartView.drawBarShadowEnabled = false
chartView.drawValueAboveBarEnabled = false

let xAxis = chartView.xAxis
xAxis.drawGridLinesEnabled = false
xAxis.labelPosition = .bottom
xAxis.centerAxisLabelsEnabled = true
xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
xAxis.granularity = 1
xAxis.labelCount = 12

let leftAxisFormatter = NumberFormatter()
leftAxisFormatter.maximumFractionDigits = 1

let yaxis = chartView.leftAxis
yaxis.spaceTop = 0.35
yaxis.axisMinimum = 0
yaxis.drawGridLinesEnabled = false

chartView.rightAxis.enabled = false

setChart()
}

func setChart() {
var dataEntries1 = [BarChartDataEntry]()
var dataEntries2 = [BarChartDataEntry]()
let xValuesForTotalGoals = [0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5]

totalGoals = data.monthly(goals: data.allGoalsObjects(achieved: false))
completedGoals = data.monthly(goals: data.allGoalsObjects(achieved: true))
for i in 0..<months.count {
dataEntries1.append(BarChartDataEntry(x: xValuesForTotalGoals[i], y: totalGoals[i]))
dataEntries2.append(BarChartDataEntry(x: Double(i), y: completedGoals[i]))
}
let chartDataSet1 = BarChartDataSet(entries: dataEntries1, label: "Total Number Of Goals")
let chartDataSet2 = BarChartDataSet(entries: dataEntries2, label: "Completed Goals")
chartDataSet1.colors = [UIColor.black]
chartDataSet1.valueTextColor = UIColor.white
chartDataSet2.colors = [UIColor.gray]
let chartData = BarChartData(dataSets: [chartDataSet1, chartDataSet2])
let barWidth = 0.5
chartData.barWidth = barWidth
chartView.notifyDataSetChanged()
chartView.data = chartData
chartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .linear)
}

enter image description here

最佳答案

我不记得属性是什么,请尝试每个属性

xAxis.enabled = false.
rightAxis.enabled = false.

关于swift - 如何禁用出现在月份标签后面的 X 轴下方的 0.0 数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59039084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com