gpt4 book ai didi

ios - 图表显示不正确? iOS 图表库

转载 作者:行者123 更新时间:2023-11-30 12:10:43 29 4
gpt4 key购买 nike

我正在使用charts用于创建这样的图形的库

enter image description here

我正在使用此代码来填充图表。下面代码中发送的数据是

[[1.6667000000000001, 2.0], [1.6667000000000001, 1.0], [1.6667000000000001, 1.0], [2.3333000000000004, 2.0], [1.3332999999999999, 1.0], [1.6667000000000001, 3.0], [1.3332999999999999, 2.0], [1.3332999999999999, 1.0], [2.3333000000000004, 3.0], [2.0, 2.0], [2.6666999999999996, 3.0], [2.3333000000000004, 1.0], [2.3333000000000004, 2.0]]

func setChart(data:[[Double]]) {
barChartView.noDataText = "You need to provide data for the chart."
var dataEntries: [[BarChartDataEntry]] = []

for _ in 0..<data.first!.count{
dataEntries.append([])
}

for i in 0..<data.count {

for g in 0..<dataEntries.count{
dataEntries[g].append(BarChartDataEntry(x: Double(i), y: data[i][g]))
}

}

var dataSet = [BarChartDataSet]()

for i in 0..<dataEntries.count {

let some = BarChartDataSet(values: dataEntries[i], label: nil)
some.colors = ChartColorTemplates.colorful()
dataSet.append(some)

}



let chartData = BarChartData(dataSets: dataSet)


let groupSpace = 0.025
let barSpace = 0.4
let barWidth = 0.8
// (0.05 + 0.03) * 3 + 0.3 = 1.00 -> interval per "group"
//(groupSpace * barSpace) * n + groupSpace = 1
//()*13
let startYear = 0


chartData.barWidth = barWidth;
barChartView.xAxis.axisMinimum = Double(startYear)
let gg = chartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)
print("Groupspace: \(gg)")
// barChartView.xAxis.axisMaximum = Double(startYear) + gg * Double(groupCount)
barChartView.xAxis.axisMaximum = 25
barChartView.groupBars(fromX: Double(startYear), groupSpace: groupSpace, barSpace: barSpace)
//chartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)
barChartView.notifyDataSetChanged()

barChartView.data = chartData






//background color
barChartView.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)

//chart animation
barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .linear)
}

这不能正常工作,我有重叠的条。 X 轴最大值不会自动创建。我不知道我在这里做错了什么。任何人都可以告诉我我错在哪里。每组的条数为 13,组数最多可达 50。

最佳答案

非常简单,您正在为 barChartView 设置 groupBars。这是错误的。

barChartView.groupBars(fromX: Double(startYear), groupSpace: groupSpace, barSpace: barSpace)

您必须为chartData设置groupBars。就像下面这样

chartData.groupBars(fromX: Double(startYear), groupSpace: groupSpace, barSpace: barSpace)

关于ios - 图表显示不正确? iOS 图表库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46099142/

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