在 WatchOs 中添加图表 [英] Adding charts in WatchOs
问题描述
我正在开发一个 POC,以在 Apple Watch 中实现图表(商业/企业数据分析).
例如:
我该怎么做?
我发现
let image = YOLineChartImage()image.strokeWidth = 4.0//线宽image.strokeColor = randomColor()//线条颜色image.values = [0.0, 1.0, 2.0]//图表值image.smooth = false//禁用平滑线image.drawImage(frame, scale: scale)//绘制图像
折线图平滑
let image = YOLineChartImage()image.strokeWidth = 4.0//线宽image.fillColor = randomColor()//区域的颜色image.values = [0.0, 1.0, 2.0]//图表值//image.smooth = true//[默认] 绘制平滑线image.drawImage(frame, scale: scale)//绘制图像
垂直条形图
let image = YOBarChartImage()image.values = [0.0, 1.0, 2.0]//图表值image.fillColor = randomColor()//条形的颜色//image.barPadding = 2.0//[可选] 条形填充//image.barStyle = .Vertical//[默认] 绘制垂直条image.drawImage(frame, scale: scale)//绘制图像
水平条形图
let image = YOBarChartImage()image.values = [0.0, 1.0, 2.0]//图表值image.fillColor = randomColor()//条形的颜色//image.barPadding = 2.0//[可选] 条形填充image.barStyle = .Horizontal//绘制一个水平条image.drawImage(frame, scale: scale)//绘制图像
圆环图
let image = YODonutChartImage()image.donutWidth = 16.0//甜甜圈的宽度//image.labelText = "LABEL"//[可选] 居中标签文本//image.labelColor = UIColor.whiteColor()//[可选] 中心标签颜色image.values = [10.0, 20.0, 70.0]//图表值image.colors = (0..<3).map { _ in randomColor() }//块的颜色image.drawImage(frame, scale: scale)//绘制图像
<小时>
框架要求
watchOS ~>2.0
构建要求
Xcode >= 7.1
<小时>
示例应用
示例应用程序适用于 iOS 和 watchOS.你可以在这里
找到所有文件pod 尝试 YOChartImageKit
或使用 Xcode 打开 YOChartImageKit.xcodeproj
并构建演示应用程序.
您可以在 GitHub 自述文件 上找到所有文档.
I am working on a POC to implement charts in Apple Watch (Analytics for Business/Enterprise data).
For example :
How can I do that ?
I found that YOChartImageKit. With this library you can create charts in watch os.
Installation
CocoaPods
use_frameworks!
pod 'YOChartImageKit', '~> 1.1'
Carthage
github "yasuoza/YOChartImageKit" ~> 1.1
CocoaSeeds
# For both iOS and watchOS framework
target 'YOChartImageKit' do
github 'yasuoza/YOChartImageKit', '1.1.0', files: 'Source/YOChartImageKit/*.{h,m}'
end
Configuration
Line chart solid
let image = YOLineChartImage()
image.strokeWidth = 4.0 // width of line
image.strokeColor = randomColor() // color of line
image.values = [0.0, 1.0, 2.0] // chart values
image.smooth = false // disable smooth line
image.drawImage(frame, scale: scale) // draw an image
Line chart smooth
let image = YOLineChartImage()
image.strokeWidth = 4.0 // width of line
image.fillColor = randomColor() // color of area
image.values = [0.0, 1.0, 2.0] // chart values
// image.smooth = true // [default] draws a smooth line
image.drawImage(frame, scale: scale) // draw an image
Bar chart vertical
let image = YOBarChartImage()
image.values = [0.0, 1.0, 2.0] // chart values
image.fillColor = randomColor() // color of bars
// image.barPadding = 2.0 // [optional] padding of bars
// image.barStyle = .Vertical // [default] draws a vertical bars
image.drawImage(frame, scale: scale) // draw an image
Bar chart horizontal
let image = YOBarChartImage()
image.values = [0.0, 1.0, 2.0] // chart values
image.fillColor = randomColor() // color of bars
// image.barPadding = 2.0 // [optional] padding of bars
image.barStyle = .Horizontal // draws a horizontal bars
image.drawImage(frame, scale: scale) // draw an image
Donut chart
let image = YODonutChartImage()
image.donutWidth = 16.0 // width of donut
// image.labelText = "LABEL" // [optional] center label text
// image.labelColor = UIColor.whiteColor() // [optional] center label color
image.values = [10.0, 20.0, 70.0] // chart values
image.colors = (0..<3).map { _ in randomColor() } // colors of pieces
image.drawImage(frame, scale: scale) // draw an image
Framework Requirements
watchOS ~> 2.0
Build Requirements
Xcode >= 7.1
Example Application
Example applications are available for both iOS and watchOS. You can find all file here
pod try YOChartImageKit
or open YOChartImageKit.xcodeproj
with Xcode and build demo app.
You can find all the documentation on the GitHub readme.
这篇关于在 WatchOs 中添加图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!