gpt4 book ai didi

ios - X 轴值重叠 - iOS 图表

转载 作者:行者123 更新时间:2023-11-28 05:38:11 31 4
gpt4 key购买 nike

这是图 TableView 的屏幕截图。

enter image description here

我正在使用 ios https://github.com/danielgindi/Charts图书馆

x 轴上的值(日期)重叠。

 axisMinValue = 50.0
axixMaxvalue = 300.0

unitsSold = [65.0,88.0, 114.0, 111.0, 88.0 ]
months = ["Sep 12, 2019”,"Sep 12, 2019”,"Sep 12, 2019”,"Sep 11, 2019”,"Sep 11, 2019"]

这是我写的代码,

    if unitsSold.count < 1{

cell.chartViewOutlet.noDataText = "No data available!"
}
else{

dataEntries = []
for i in 0 ..< unitsSold.count {
let dataEntry = ChartDataEntry(x: Double(i), y: unitsSold[i])
dataEntries.append(dataEntry) // here we add it to the data set
}

let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Consumed")

lineChartDataSet.setCircleColor(UIColor.clear) // hide the outer circle color
lineChartDataSet.circleRadius = 0.0
lineChartDataSet.lineWidth = 2.0 //1.0
lineChartDataSet.valueTextColor = UIColor.clear //hide the values on the curve line


lineChartDataSet.colors = [NSUIColor.blue] //Sets the line colour to blue
lineChartDataSet.mode = .cubicBezier
lineChartDataSet.cubicIntensity = 0.2

var dataSets = [LineChartDataSet]()
dataSets.append(lineChartDataSet)

let lineChartData = LineChartData(dataSets: dataSets)
cell.chartViewOutlet.data = lineChartData

cell.chartViewOutlet.chartDescription?.text = ""

cell.chartViewOutlet.xAxis.enabled = true
cell.chartViewOutlet.leftAxis.enabled = true
cell.chartViewOutlet.rightAxis.enabled = false
cell.chartViewOutlet.animate(xAxisDuration: 1.5)
cell.chartViewOutlet.drawGridBackgroundEnabled = true




cell.chartViewOutlet.xAxis.drawGridLinesEnabled = true
cell.chartViewOutlet.xAxis.drawAxisLineEnabled = true

cell.chartViewOutlet.xAxis.labelPosition = .bottom
cell.chartViewOutlet.xAxis.drawLabelsEnabled = true


cell.chartViewOutlet.leftAxis.drawGridLinesEnabled = true

cell.chartViewOutlet.legend.enabled = false //show.hide legend - below graph


let customFormater = CustomFormatter1()
customFormater.labels = months
cell.chartViewOutlet.xAxis.valueFormatter = customFormater

//在 x 轴上显示值

final class CustomFormatter1: IAxisValueFormatter {

var labels: [String] = []

func stringForValue(_ value: Double, axis: AxisBase?) -> String {

let count = self.labels.count

guard let axis = axis, count > 0 else {
return ""
}

let factor = axis.axisMaximum / Double(count)

let index = Int((value / factor).rounded())

if index >= 0 && index < count {
return self.labels[index]
}

return ""
}

我们如何解决这个重叠问题?或者有什么办法可以让这个值根据屏幕或月份的长度自动调整?

最佳答案

尝试使用以下并尝试,它会工作 100%

cell.chartViewOutlet.xAxis.labelRotationAngle = -45

关于ios - X 轴值重叠 - iOS 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57900705/

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