如何在 iOS 中使用 JBLineChart 绘制和自定义两条线?
How do I plot and customize two lines with JBLineChart in iOS?
我正在尝试使用 Jawbone 的 iOS 图形库在一张图表上绘制两组数据。这是日期(x 轴)、activity 级别和阈值的数据:
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 中的编码还很陌生,只找到了关于此主题的有限文档。感谢您提供的任何帮助!
func lineChartView(_ lineChartView: JBLineChartView!, verticalValueForHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> CGFloat {
if (lineIndex == 0) {
return CGFloat(activityChartData[Int(horizontalIndex)])
}
else if (lineIndex == 1)
{
return CGFloat(activityChartData2[Int(horizontalIndex)])
}
return 0
}
其他功能同理。你会注意到他们有自己的 lineIndex
:D
我正在尝试使用 Jawbone 的 iOS 图形库在一张图表上绘制两组数据。这是日期(x 轴)、activity 级别和阈值的数据:
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 中的编码还很陌生,只找到了关于此主题的有限文档。感谢您提供的任何帮助!
func lineChartView(_ lineChartView: JBLineChartView!, verticalValueForHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> CGFloat {
if (lineIndex == 0) {
return CGFloat(activityChartData[Int(horizontalIndex)])
}
else if (lineIndex == 1)
{
return CGFloat(activityChartData2[Int(horizontalIndex)])
}
return 0
}
其他功能同理。你会注意到他们有自己的 lineIndex
:D