gpt4 book ai didi

ios - 条形图上方的标签不显示水平条形图 ios-charts

转载 作者:行者123 更新时间:2023-11-28 18:50:49 27 4
gpt4 key购买 nike

我正在我的项目中为水平条形图实现 ios-charts。我需要各个条形图的值出现在条形图上方(因为图表是水平的,标签应该出现在条形图的右侧)。但是,我无法让它工作。代码如下:

func setupHorizontalChartView() {

self.chartView.chartDescription?.enabled = false
chartView.dragEnabled = false
chartView.setScaleEnabled(true)
chartView.pinchZoomEnabled = false

let chartXAxis = chartView.xAxis
chartXAxis.labelPosition = .bottom

let chartLeftAxis = chartView.leftAxis
chartLeftAxis.labelFont = NSUIFont(name: "Helvetica", size: 12)!
chartLeftAxis.labelTextColor = UIColor.darkGray

chartView.rightAxis.enabled = false

chartView.drawValueAboveBarEnabled = true

let formatter = BarChartFormatter()
formatter.setValues(values: self.months)

chartView.xAxis.valueFormatter = formatter
chartView.xAxis.setLabelCount(self.months.count - 1, force: false)

chartView.xAxis.drawGridLinesEnabled = false
chartView.leftAxis.drawGridLinesEnabled = false

chartView.xAxis.drawAxisLineEnabled = false
chartView.leftAxis.drawAxisLineEnabled = false

chartView.leftAxis.drawLabelsEnabled = false
}

func setChart(dataPoints: [String], values: [Double]) {

var dataEntries: [BarChartDataEntry] = []

for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}

let chartDataSet = BarChartDataSet(values: dataEntries, label: "Units Sold")

chartDataSet.drawValuesEnabled = true
let chartData = BarChartData(dataSet: chartDataSet)
chartData.setDrawValues(true)

chartView.data = chartData
}

drawValueAboveBarEnabled 已为 chartView 设置为 true。当我对 BarChartView 而不是 Horizo​​ntalBarChartView 使用相同的代码时,条形图的值显示在条形图上方。但是,它不适用于水平条形图 View 。

最佳答案

设置chartView.leftAxis.axisMinimum = 0帮助过我。我在这里打开了一个讨论 GitHub

关于ios - 条形图上方的标签不显示水平条形图 ios-charts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41265190/

27 4 0