迁移到Swift 3后,我的折线图在y轴上显示奇怪的值。我不确定是否是有问题的范围或数据集。但我检查了y值似乎是正确的。 图表本身也显示为蓝色矩形而不是折线图(我假设因为错误的y值) 通过查看此图表,任何人都会知道可能出现的问题吗?
更新 我能够将问题精确定位到未正确设置的右轴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
}
答案 0 :(得分:0)
我没有看到您将数据集axisDependency
设置为右轴。