如何设置y轴最小值Swift 3

时间:2022-09-26 19:03:45

I am trying to set a minimum y-axis value of 300 in swift 3 using the following code:

我试图使用以下代码在swift 3中设置最小y轴值300:

In viewDidLoad:

在viewDidLoad中:

    barChartView.noDataText = "No information available."
    barChartView.xAxis.labelPosition = .bothSided
    barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5)
    let ll = ChartLimitLine(limit: 300, label: "Target")
    barChartView.rightAxis.addLimitLine(ll)
    barChartView.chartDescription?.enabled = false
    barChartView.leftAxis.axisMinimum = 300;
    updateChartWithData(dataPoints: stringOfDate, values: totalNumber)




 func updateChartWithData(dataPoints: [String], values: [Int]) {
    var dataEntries: [BarChartDataEntry] = []
    for i in 0..<values.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: Double(values[i]))
        dataEntries.append(dataEntry)
    }
    let chartDataSet = BarChartDataSet(values: dataEntries, label: "Total Number")
    let chartData = BarChartData(dataSet: chartDataSet)
    barChartView.data = chartData
}

However when I use this code the minimum does not set to 300 and the bars in my bar chart no longer display.

但是,当我使用此代码时,最小值不会设置为300,并且条形图中的条形不再显示。

1 个解决方案

#1


1  

If I set

如果我订

barChartView.leftAxis.axisMinimum = 0

barChartView.leftAxis.axisMinimum = 0

I get: 如何设置y轴最小值Swift 3

我明白了:

Then if I set:

如果我设置:

barChartView.leftAxis.axisMinimum = 13

barChartView.leftAxis.axisMinimum = 13

I get: 如何设置y轴最小值Swift 3

我明白了:

In the second graph all the bars with value lower than 13 are hidden. You didn´t show the data points in your code, but I think they must all be lower than 300 and that´s why they are hidden.

在第二个图中,隐藏了值小于13的所有条形图。您没有在代码中显示数据点,但我认为它们必须都低于300,这就是隐藏它们的原因。

#1


1  

If I set

如果我订

barChartView.leftAxis.axisMinimum = 0

barChartView.leftAxis.axisMinimum = 0

I get: 如何设置y轴最小值Swift 3

我明白了:

Then if I set:

如果我设置:

barChartView.leftAxis.axisMinimum = 13

barChartView.leftAxis.axisMinimum = 13

I get: 如何设置y轴最小值Swift 3

我明白了:

In the second graph all the bars with value lower than 13 are hidden. You didn´t show the data points in your code, but I think they must all be lower than 300 and that´s why they are hidden.

在第二个图中,隐藏了值小于13的所有条形图。您没有在代码中显示数据点,但我认为它们必须都低于300,这就是隐藏它们的原因。