ios - Swift:从两个数组转换为数据集以在图表中使用

标签 ios arrays swift dataset

<分区>

我有两个 double 组:

x = [(1.0, 2.0, 3.0, 4.0, 5.0)]
y = [(3.0, 4.0, 5.0, 6.0, 7.0)]

我想在此代码行中使用这些变量 xy(而不是固定值):

(chartPoints: [(2.0, 2.6),....], color: UIColor.redColor())

我怎样才能将它们组合起来,使我拥有 [(Double, Double)] 类型的东西?

最佳答案

我不确定我是否正确理解了您的问题,但可以创建一个 CGPoint 数组:

let a: Array<CGFloat> = [1, 2, 3]
let b: Array<CGFloat> = [6, 7, 8]
var c = Array<CGPoint>()

for i in 0..<a.count {
    if i < b.count {
        c.append(CGPointMake(a[i], b[i]))
    }
}

关于ios - Swift:从两个数组转换为数据集以在图表中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39209399/

相关文章:

ios - 添加 UItextField 输入并将其保存到数组

arrays - Swift 中 u_int8_t 的 Objective-C 数组

ios - UITableViewCell 中的 UITextField 使用单元格的 imageView

java - 从字节数组中删除多余的 "empty"字符并转换为字符串

javascript - 对除一项之外的一组名称进行排序

ios - 在 cellForItemAt Collection View 中,不会通过 swift 3 中的 collectionView.reloadData() 更新 indexPath

ios - Sqlite for iOS 在 Swift 中编译的线程模式是什么?

ios - 如何在 swift 4 中使用 Share 类过滤 searchController 中的数据

iphone - MvvmCross:GestureRecognized 绑定(bind)到 ViewModel 操作

iphone - 制作一个可以连接另一个蓝牙设备的简单iphone应用程序