gpt4 book ai didi

ios - iOS Charts X Axis标签未全部显示

转载 作者:行者123 更新时间:2023-12-01 18:39:52 27 4
gpt4 key购买 nike

我的应用程序管理一项具有四个季度周期的运动的得分。我的条形图将无法正确显示x轴标签。它仅显示Qtr 1和Qtr 3,而应显示每个条形对下的所有四个季度。
Screen shot of Bar Chart

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

let legend = barChartView.legend
legend.enabled = true
legend.textColor = Style.labelTextColor

let xaxis = barChartView.xAxis
xaxis.drawGridLinesEnabled = true
xaxis.labelPosition = .bottom
xaxis.axisMinimum = 0
xaxis.centerAxisLabelsEnabled = true
xaxis.granularityEnabled = true
xaxis.labelCount = 4
xaxis.granularity = 2
xaxis.labelTextColor = Style.labelTextColor

let leftAxisFormatter = NumberFormatter()
leftAxisFormatter.maximumFractionDigits = 1

let yaxis = barChartView.leftAxis
yaxis.spaceTop = 0.35
yaxis.axisMinimum = 0
yaxis.drawGridLinesEnabled = true
yaxis.labelTextColor = Style.labelTextColor
yaxis.gridColor = Style.labelTextColor
yaxis.zeroLineColor = Style.labelTextColor
yaxis.axisLineColor = Style.labelTextColor

barChartView.rightAxis.enabled = false

barChartView.noDataText = "You need to provide data for the chart."
barChartView.chartDescription?.text = nil

var dataEntries1: [BarChartDataEntry] = []; var dataEntries2: [BarChartDataEntry] = []

for i in 0..<dataPoints.count {
let dataEntry1 = BarChartDataEntry(x: Double(i), y: values1[i])
dataEntries1.append(dataEntry1)

let dataEntry2 = BarChartDataEntry(x: Double(i), y: values2[i])
dataEntries2.append(dataEntry2)
}

let chartDataSet1 = BarChartDataSet(values: dataEntries1, label: gCurrentMatch.teamA)
let chartDataSet2 = BarChartDataSet(values: dataEntries2, label: gCurrentMatch.teamB)
chartDataSet1.colors = [Style.chartColorA]; chartDataSet1.valueColors = [Style.labelTextColor]
chartDataSet2.colors = [Style.chartColorB]; chartDataSet2.valueColors = [Style.labelTextColor]

let dataSets: [BarChartDataSet] = [chartDataSet1, chartDataSet2]
let chartData = BarChartData(dataSets: dataSets)

let groupSpace = 0.3
let barSpace = 0.05
let barWidth = 1.0
// (0.3 + 0.05) * 2 + 0.3 = 1.00 -> interval per "group"

let groupCount = self.qtr.count

chartData.barWidth = barWidth
let gg = chartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)

barChartView.xAxis.axisMaximum = Double(0) + gg * Double(groupCount)
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)

chartData.groupBars(fromX: Double(0), groupSpace: groupSpace, barSpace: barSpace)
barChartView.notifyDataSetChanged()
barChartView.data = chartData
//chart animation
barChartView.animate(yAxisDuration: 0.5, easingOption: .linear)

}

dataPoints是包含“Qtr 1”,“Qtr 2”等的字符串数组。

我无法弄清楚为什么它不起作用。

最佳答案

在xaxis格式中使用以下代码:

xaxis.setLabelCount(4, force: true)

关于ios - iOS Charts X Axis标签未全部显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44914636/

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