swiftui - 在 SwiftUI 中绘制折线图
问题描述
我正在尝试在 Swift UI 中绘制折线图,但无法实现 for 循环:
Path { path in
path.move(to: CGPoint(x: 20, y: 20))
ForEach(0 ..< 11) { index in
path.addLine(to: CGPoint(x: ((index * 20) + 40), y: Int(hr[index])))
}
给我一个构建错误:
类型 '()' 不能符合 'View';只有结构/枚举/类类型可以符合协议
解决方案
这是解决方案的演示:
Path { path in
path.move(to: CGPoint(x: 20, y: 20))
for index in 0 ..< 11 {
path.addLine(to: CGPoint(x: ((index * 20) + 40), y: y_pos[index]))
}
}
// .stroke(Color.red) // for demo stroked if inside ViewBuilder
推荐阅读
- java - 在 Java 中禁用 SSL 证书验证
- java - 使用 Eclipse 从代码中的未知位置进行调试,有可能吗?
- java - Instance variables behaviour in multithreading
- python - Index a string slice from it's end with a variable in python doesn't provide generic acces to last element
- android - 如何等待 ObservableEmitter 返回 onComplete()
- javascript - React Native如何改变secureTextEntry输入的大小和颜色
- node.js - Add prefix to all api's in hapi
- javascript - 将列表中的值绑定到变量以进行 api 查询
- dart - Flutter firebase_admob 只显示一次
- javascript - 如何将 html 和 js 代码包含到一个 js 文件中?