0
我正在嘗試使用Jawbone的iOS圖形庫在一張圖表上繪製兩組數據。下面是時間(x軸),活動水平和閾值中的數據:如何在iOS中繪製和定製兩行JBLineChart?
var activityChartLegend = ["11-14", "11-15", "11-16", "11-17", "11-18", "11-19", "11-20"]
var activityChartData = [88, 81, 69, 77, 70, 89, 90]
var activityThreshold = [80, 80, 80, 80, 80, 80, 80]
我已成功地繪製activityChartData的第一行。然而,我很困惑如何繪製activityThreshold的第二行。文檔有限,所以我不確定如何繪製第二行。在下面的代碼中,我已將行數返回爲「2」,但我不明白如何在以下函數中繪製兩行。
func numberOfLines(in lineChartView: JBLineChartView!) -> UInt {
return 2
}
func lineChartView(_ lineChartView: JBLineChartView!, numberOfVerticalValuesAtLineIndex lineIndex: UInt) -> UInt {
if (lineIndex == 0) {
return UInt(activityChartData.count)
}
return 0
}
func lineChartView(_ lineChartView: JBLineChartView!, verticalValueForHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> CGFloat {
if (lineIndex == 0) {
return CGFloat(activityChartData[Int(horizontalIndex)])
}
return 0
}
而且,我已經格式化爲具有如下的第一行代碼,但不知道如何格式化其他線路一旦成功添加到圖表視圖:
func lineChartView(_ lineChartView: JBLineChartView!, showsDotsForLineAtLineIndex lineIndex: UInt) -> Bool {
return true // False = do not show the dots
}
func lineChartView(_ lineChartView: JBLineChartView!, dotRadiusForDotAtHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> CGFloat {
return CGFloat(6)
}
func lineChartView(_ lineChartView: JBLineChartView!, colorForDotAtHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> UIColor! {
return UIColor.lightGray
}
func lineChartView(_ lineChartView: JBLineChartView!, smoothLineAtLineIndex lineIndex: UInt) -> Bool {
return true
}
func lineChartView(_ lineChartView: JBLineChartView!, didSelectLineAt lineIndex: UInt, horizontalIndex: UInt) {
if (lineIndex == 0){
let data = activityChartData[Int(horizontalIndex)]
let key = activityChartLegend[Int(horizontalIndex)]
activityLabel.text = "Number of steps on \(key): \(data)"
}
}
我相當在iOS中編程的新手只有在這個主題上找到有限的文檔。感謝您提供任何幫助!