iso-charts 折线图右轴最小值和最大值设置不正确

iso-charts Line Chart right axis min and max values not set properly

迁移到 Swift 3 后,我的折线图在 y 轴上显示了奇怪的值。我不确定是范围还是数据集有问题。但我检查了一下,y 值似乎是正确的。 图表本身也显示为蓝色矩形而不是折线图(我假设是因为错误的 y 值) 看看这张图表,有人会知道哪里出了问题吗?

Chart

更新: 我能够将问题精确定位到未正确设置的右轴 axisMinimum 和 axisMaximum。当我对左轴使用相同的代码时,它工作得很好。

这里是设置代码:

class func newLineChartViewWithXValsAndDataSets(frame: CGRect, xVals: [String], dataSets: [SVLineChartDataSet]?, maximum: ChartDataEntry?, minimum: ChartDataEntry?) -> LineChartView {
    let lineChartView = LineChartView(frame: frame)
    let chartData = LineChartData(dataSets: dataSets)
    let margin: CGFloat = 6
    lineChartView.doubleTapToZoomEnabled = false
    lineChartView.dragEnabled = false
    lineChartView.drawGridBackgroundEnabled = false
    lineChartView.drawBordersEnabled = false
    lineChartView.legend.textColor = UIColor.sharevilleLightGrey

    lineChartView.xAxis.labelPosition = .bottom
    lineChartView.xAxis.labelTextColor = UIColor.sharevilleLightGrey
    lineChartView.xAxis.avoidFirstLastClippingEnabled = true
    lineChartView.xAxis.drawGridLinesEnabled = false
    lineChartView.xAxis.axisLineColor = UIColor.sharevilleTouchGrey
    lineChartView.xAxis.valueFormatter = LineChartDateFormatter(dates: xVals)
    lineChartView.xAxis.setLabelCount(3, force: true)

    lineChartView.leftAxis.axisLineColor = UIColor.sharevilleTouchGrey
    //lineChartView.leftAxis.drawLabelsEnabled = false
    //lineChartView.leftAxis.drawAxisLineEnabled = false
    lineChartView.leftAxis.spaceTop = margin
    lineChartView.leftAxis.spaceBottom = margin
    lineChartView.leftAxis.resetCustomAxisMax()
    lineChartView.leftAxis.resetCustomAxisMin()

    lineChartView.rightAxis.labelTextColor = UIColor.sharevilleDarkGrey
    lineChartView.rightAxis.axisLineColor = UIColor.sharevilleTouchGrey
    lineChartView.rightAxis.gridColor = UIColor.sharevilleTouchGrey
    lineChartView.rightAxis.labelPosition = .insideChart
    lineChartView.rightAxis.drawLabelsEnabled = false
    lineChartView.rightAxis.drawAxisLineEnabled = false
    lineChartView.rightAxis.spaceTop = margin
    lineChartView.rightAxis.spaceBottom = margin


    // if we have no maximum and minimumvalue return the linechart directly
    guard let maximum = maximum, let minimum = minimum else {
        return lineChartView
    }

    //let absMinMax = abs(maximum.y - minimum.y)
    //let visibleYRangeMaxium = max(absMinMax,1) * 1.2
   // print("visibile Y Range")
   // print(visibleYRangeMaxium)

    //lineChartView.setVisibleYRangeMaximum(visibleYRangeMaxium, axis: YAxis.AxisDependency.left)

    lineChartView.leftAxis.axisMinimum =  minimum.y
    lineChartView.leftAxis.axisMaximum =  maximum.y
    //lineChartView.rightAxis.axisMinimum =  minimum.y
    //lineChartView.rightAxis.axisMaximum =  maximum.y


    lineChartView.animate(xAxisDuration: 1, easingOption: .easeInCubic)

    print("LinChartView.data= ", lineChartView.data)
    lineChartView.chartDescription?.text = ""
    lineChartView.backgroundColor = .white


    if let dataSets = dataSets {
        for dataSet in dataSets {

            if dataSet.isLineChartViewHighLowEnabled {
                DispatchQueue.main.async {
                    self.drawLineChartValueView(lineChartView, dataEntry: maximum)
                    self.drawLineChartValueView(lineChartView, dataEntry: minimum)
                }
            }
        }
    }

    lineChartView.data = chartData

    return lineChartView
}

我没有看到您将数据集 axisDependency 设置为右轴。