gpt4 book ai didi

ios - 在 ios-charts 中如何设置 y 轴的最大值?

转载 作者:搜寻专家 更新时间:2023-11-01 06:08:22 24 4
gpt4 key购买 nike

我正在使用 ios-charts 来显示一个具有如下值的水平条形图:

 var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: self.deductible!.deductiblePaid, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Deductible")
let chartData = BarChartData( xVals: dataPoints, dataSet: chartDataSet)


self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.customAxisMax = 3000.0
self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false

chartDataSet.colors = ChartColorTemplates.vordiplom()

我已尝试为 YAxis 设置最大值,但它不会影响图表。编辑:请在此处查看屏幕截图:http://postimg.org/image/ogoj2t02f/我需要的是条形图应该显示最高 3000(或动态指定的数量)的上限,而不是计算出的上限。

我更改了一些代码来实现它,这是我目前拥有的:

self.horizontalBarChart!.noDataText = "You need to provide data for the chart."

self.horizontalBarChart!.setVisibleYRangeMaximum(3000, axis: ChartYAxis.AxisDependency.Left)
self.horizontalBarChart!.descriptionText = ""
var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: self.deductible!.deductiblePaid, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: " ")
self.horizontalBarChart!.noDataText = "You need to provide data for the chart."
self.horizontalBarChart!.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0);
let chartData = BarChartData( xVals: dataPoints, dataSet: chartDataSet)

self.horizontalBarChart!.autoScaleMinMaxEnabled = false
self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.axisMaximum = 1600
self.horizontalBarChart!.leftAxis.axisMinimum = 00
self.horizontalBarChart!.rightAxis.axisMaximum = 1600
//self.horizontalBarChart!.leftAxis.customAxisMax = 3000.0
//self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false

chartDataSet.colors = ChartColorTemplates.vordiplom()
self.horizontalBarChart!.xAxis.labelPosition = .Top

self.horizontalBarChart!.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)
self.horizontalBarChart!.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)

如果我不清楚并且您需要更多详细信息,请告诉我。这比我想象的更具挑战性!这里的任何帮助将不胜感激。

第二次编辑:我现在有以下代码:

 func setHorizontalBarChartData() {

self.horizontalBarChart!.descriptionText = ""
var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: 900, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: " ")
self.horizontalBarChart!.noDataText = "You need to provide data for the chart."
//self.horizontalBarChart!.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0);
let deductible = [" "]
let chartData = BarChartData( xVals: deductible, dataSet: chartDataSet)
self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false
self.horizontalBarChart!.rightAxis.startAtZeroEnabled = false
self.horizontalBarChart!.rightAxis.customAxisMax = 3000
self.horizontalBarChart!.rightAxis.customAxisMin = 10
chartDataSet.colors = ChartColorTemplates.vordiplom()
self.horizontalBarChart!.xAxis.labelPosition = .Top
self.horizontalBarChart!.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)
self.horizontalBarChart!.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
}

我仍然得到同样的结果:http://postimg.org/image/ogoj2t02f/我只需要一个值高达 3000 的条形图和一个高达 900 的条形图。你能帮忙吗?

最佳答案

如果上下 y 轴值未按预期显示,请确保

  1. 您在 y 轴的左右两侧设置了 customAxisMaxcustomAxisMin
  2. 在设置图 TableView 的.data 之前设置customAxisMaxcustomAxisMax
  3. 您将 x 轴和 y 轴的 startAtZeroEnabled 设置为 false。在设置图 TableView 的 .data 之前设置 startAtZeroEnabled

我花了几个小时才弄明白这些。希望它可以为您节省一些。

关于ios - 在 ios-charts 中如何设置 y 轴的最大值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31389081/

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