我知道有一个chart.leftAxis.startAtZeroEnabled = false
选项,但它不适用于我。
我制作了一个线图来追踪Instagram追随者随着时间的推移而且我的数据点变化很小所以我需要调整y轴以便更改已启用,但它
以下是我对图表的代码:
let chart = LineChartView(frame: chart1View.bounds)
let dayTrackerUnits = trackerCrawler.thisWeeksPoints()
var xVals : [Int] = []
var yVals : [ChartDataEntry] = []
var minimum = 1000000000
var maximum = 0
for i in 0..<dayTrackerUnits.count {
xVals.append(i)
yVals.append(ChartDataEntry(value: Double(dayTrackerUnits[i].followerCount), xIndex: i))
if dayTrackerUnits[i].followerCount < minimum {
minimum = dayTrackerUnits[i].followerCount
}
if dayTrackerUnits[i].followerCount > maximum {
maximum = dayTrackerUnits[i].followerCount
}
}
print(yVals)
let chartDataSet = LineChartDataSet(yVals: yVals, label: "Followers")
chartDataSet.setColor(GlobalStyles.sharedStyles.instagramBlue())
chartDataSet.lineWidth = 2.0
chartDataSet.circleRadius = 5.0
chartDataSet.circleColors = [GlobalStyles.sharedStyles.instagramBlue()]
chartDataSet.drawValuesEnabled = false
chartDataSet.drawVerticalHighlightIndicatorEnabled = true
let data = LineChartData(xVals: xVals, dataSet: chartDataSet)
chart.data = data
chart.delegate = self
chart.leftAxis.startAtZeroEnabled = false
chart.rightAxis.startAtZeroEnabled = false
print("min: \(minimum), max: \(maximum)")
chart.rightAxis.enabled = false
chart1View.addSubview(chart)
left1Label.text = "Followers"
我想将yAxisMinimum
设置为minimum
,将yAxisMaximum
设置为maximum
,但图表不会显示我想要的内容。< / p>
有什么建议吗?
答案 0 :(得分:0)
您可以使用customAxisMin/Max
来限制其范围。